Skip to content

DB connection failed when multiple test class (lifecycle issue) #7323

Closed Answered by junha-ahn
junha-ahn asked this question in Q&A
Discussion options

You must be logged in to vote

I solved this problem, just do not use @testcontainer anotation

Because

  1. @testcontainer start container when first method in a ONE Test Class, and stop if the last method finisehd
  2. It means If you start a new test class it will START NEW CONTAINER (- NEW PORT)
  3. I setup db url once, but CONTAINER PORT WILL CHANGE (when another test class start!)

How to Avoid THIS

  1. manually start/stop Container
  2. USE @DirtiesContext every test class
@SpringBootTest
@Testcontainers
abstract class AbstractIntegrationTest {

    companion object {
        val mysqlContainer = MySQLContainer("mysql:8.0.33")
            .withConfigurationOverride("./db/mysql/conf.d")

        @JvmStatic
        @DynamicPropertySou…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by junha-ahn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant