To use testcontainers scalatest suites you need to declare, which containers you want to use inside your tests.
To use testcontainers scalatest suites you need to declare, which containers you want to use inside your tests.
For example:
override type Containers = MySQLContainer
If you want to use multiple containers inside your tests, use and
syntax:
override type Containers = MySQLContainer and PostgreSQLContainer
Override, if you want to do something after containers start.
Override, if you want to do something after containers start.
Override, if you want to do something before containers stop.
Override, if you want to do something before containers stop.
Contains containers startup logic.
Contains containers startup logic. In this method you can use any intermediate logic. You can pass parameters between containers, for example:
override def startContainers(): Containers = { val container1 = Container1.Def().start() val container2 = Container2.Def(container1.someParam).start() container1 and container2 }
Started containers
To use containers inside your test bodies you need to use withContainers
function:
To use containers inside your test bodies you need to use withContainers
function:
it should "test" in withContainers { mysqlContainer => // Inside your test body you can do with your container whatever you want to assert(mysqlContainer.jdbcUrl.nonEmpty) }
withContainers
also supports multiple containers:
it should "test" in withContainers { case mysqlContainer and pgContainer => // test body }
Test body
(Since version ) see corresponding Javadoc for more information.
Starts a single container before all tests and stop it after all tests
Example: