TestContainerForAll

Starts a single container before all tests and stops it after all tests

Example:

class MysqlSpec extends FunSuite with TestContainerForAll {

 // You need to override `containerDef` with needed container definition
 override val containerDef = MySQLContainer.Def()

 // To use containers in tests you need to use `withContainers` function
 test("test case name") {
   withContainers { mysqlContainer =>
     // Inside your test body you can do with your container whatever you want to
     assert(mysqlContainer.jdbcUrl.nonEmpty)
   }
 }
}

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

Type members

Types

final override type Containers = Container

Value members

Concrete methods

override def startContainers(): Container
Definition Classes

Inherited methods

override def afterAll(): Unit
Definition Classes
Inherited from:
TestContainersForAll
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
override def afterEach(context: <none>): Unit
Definition Classes
Inherited from:
TestContainersForAll
override def beforeAll(): Unit
Definition Classes
Inherited from:
TestContainersForAll
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
override def beforeEach(context: <none>): Unit
Definition Classes
Inherited from:
TestContainersForAll
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

Abstract fields

val containerDef: ContainerDef

Inherited fields

val suiteDescription: TestDescription
Inherited from:
TestContainersSuite

Implicits

Deprecated and Inherited implicits

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