0
votes

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?rieckpil

1 Answers

1
votes

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