TestContainerForEach

Starts a single container before each test and stops it after each test

Example:

class MysqlSpec extends FunSuite with TestContainerForEach {

 // 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 beforeEach() without calling super.beforeEach() your container won't start
- If you override afterEach() without calling super.afterEach() 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

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:
TestContainersForEach
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:
TestContainersForEach
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", "v0.38.7")
implicit def stringToDockerImageName(s: String): DockerImageName
Deprecated
Inherited from:
DockerImageNameConverters