0

I have worked spring boot + testcontainers test based on JUnit 4.

Example:

@RunWith(SpringRunner.class)
@SpringBootTest
public Test {
    ...
    public void someTest() {
        ...
    }
    ...
}

test properties:

spring:
  datasource:
    driver-class-name: org.testcontainers.jdbc.ContainerDatabaseDriver
    url: jdbc:tc:mysql:5.6://hostname/db?TC_MY_CNF=mysql
    username: user
    password: pass

this test works properly, testcontainers uses JDBC Url string to initiate test container with MySQL 5.6.

Now I wanted to remove junit 4 from the project in favor to use JUnit 5.

Does testcontainers + Spring boot have ability to initiate containers in the similar way (by using JDBC URL) but using JUnit 5?

If yes - how to do it, or which workaround may be used here?

Eugene Stepanenkov
  • 896
  • 16
  • 34

1 Answers1

2

The JDBC URL style containers are testing framework agnostic, you can use it with any framework as long as you run it on JVM :)

bsideup
  • 2,845
  • 17
  • 21
  • 1
    yes you are right, my problem was that I excluded junit4 from mysql container maven dependency, `ClassNotFound` is thrown in that case (for `TestRule` class). So it has dependency to junit4. When I removed excluding it works – Eugene Stepanenkov Mar 23 '19 at 09:55