0

I have a junit test, making use of testcontainers-1.15.1. How can I start an explicit image? Because:

@SpringBootTest public class ContainerTest { private final JdbcDatabaseContainer DB = new MariaDBContainer("mariadb:10.5.8"); static { DB.start(); } @Test public void test() { } } 

Result: the default 10.3.6 container is started.

[][] 2021-02-04 14:32:50,741 INFO ?.3.6]: Creating container for image: mariadb:10.3.6 [][] 2021-02-04 14:32:51,597 INFO ?.3.6]: Container mariadb:10.3.6 is starting: d9ccf77f4b9165ccd1690ee5cb8437f43e7d853dfe5121d468a391d67eccef7d 

application.properties:

spring.datasource.url=jdbc:tc:mariadb:///test spring.datasource.username=test spring.datasource.password=test 
1
  • which version of Testcontainers are you using? Commented Feb 4, 2021 at 17:00

1 Answer 1

1

This might due to an inconsistent behavior of the constructors of the different Testcontainers modules in the past. It was fixed with this commit and should be available since Testcontainers 1.15.0.

Not sure if your sample was pseudo test code, but the following example is a valid copy-pastable example:

public class MariaDbContainerTest { private static final JdbcDatabaseContainer DB = new MariaDBContainer("mariadb:10.5.8"); static { DB.start(); } @Test public void test() { } } 

I've tested it for both Testcontainers 1.15.0 and 1.15.1 and it works on my machine.

UPDATE: I've not seen that you also specify the JDBC support of Testcontainers inside your application.properties file in addition to your manual container definition as part of your test.

Pick either the JDBC support OR the manual container definition and your problem should be resolved.

When using the JDBC support you can also specify the version of your database: jdbc:tc:mariadb:10.5.8:///test

Sign up to request clarification or add additional context in comments.

12 Comments

Strange, I'm also on 1.15.1. Could this be somehow any caching issue? Is there a cache for testcontainers explicit?
Not that I'm aware of. But you can still try to remove the relevant Docker images first
Where would I have to remove it?
Inside a shell with the following command docker rmi <nameOfTheImage>. With docker images you get an overview of all your downloaded images.
Yes, ok. I also just learned that forcing reuse from classpath only is not possible unfortunately.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.