TestContainersForAll

Starts containers before all tests and stop then after all tests

Example:

class ExampleSpec extends FunSuite with TestContainersForAll {

 // First of all, you need to declare, which containers you want to use
 override type Containers = MySQLContainer and PostgreSQLContainer

 // After that, you need to describe, how you want to start them,
 // In this method you can use any intermediate logic.
 // You can pass parameters between containers, for example.
 override def startContainers(): Containers = {
   val container1 = MySQLContainer.Def().start()
   val container2 = PostgreSQLContainer.Def().start()
   container1 and container2
 }

 // `withContainers` function supports multiple containers:
 test("test") {
   withContainers { case mysqlContainer and pgContainer =>
     // Inside your test body you can do with your containers whatever you want to
     assert(mysqlContainer.jdbcUrl.nonEmpty && pgContainer.jdbcUrl.nonEmpty)
   }
 }
}

Notes:
- If you override beforeAll() without calling super.beforeAll() your containers won't start
- If you override afterAll() without calling super.afterAll() your containers won't stop
trait DockerImageNameConverters
class Object
trait Matchable
class Any
Suite

Type members

Types

type Containers <: Andable

Value members

Concrete methods

override def afterAll(): Unit
Definition Classes
override def afterEach(context: <none>): Unit
Definition Classes
override def beforeAll(): Unit
Definition Classes
override def beforeEach(context: <none>): Unit
Definition Classes

Inherited methods

def afterContainersStart(containers: Containers): Unit

Override, if you want to do something after containers start.

Override, if you want to do something after containers start.

Inherited from:
TestContainersSuite
def beforeContainersStop(containers: Containers): Unit

Override, if you want to do something before containers stop.

Override, if you want to do something before containers stop.

Inherited from:
TestContainersSuite

Contains containers startup logic. In this method you can use any intermediate logic. You can pass parameters between containers, for example:

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
}
Returns:

Started containers

Inherited from:
TestContainersSuite
def withContainers[A](runTest: Containers => A): A

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:

test("test") {
 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:

test("test") {
 withContainers { case mysqlContainer and pgContainer =>
   // test body
 }
}
Value parameters:
runTest

Test body

Inherited from:
TestContainersSuite

Inherited fields

val suiteDescription: TestDescription
Inherited from:
TestContainersSuite

Implicits

Deprecated and Inherited implicits

@deprecated("Use `DockerImageName` in Container constructor instead", "v0.38.7")
implicit def stringToDockerImageName(s: String): DockerImageName
Deprecated
Inherited from:
DockerImageNameConverters