TestContainersForEach

trait TestContainersForEach extends TestContainersSuite with DockerImageNameConverters

Starts containers before each test and stop them after each test

Example:

class ExampleSpec extends AnyFlatSpec with TestContainersForEach {

 // 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:
 it should "test" in 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)
 }

}
trait DockerImageNameConverters
trait TestContainersSuite
trait SuiteMixin
class Object
trait Matchable
class Any

Type members

Inherited types

type Containers <: Andable

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
Inherited from
TestContainersSuite

Value members

Concrete methods

protected def runTest(testName: String, args: Args): Status

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
def expectedTestCount(filter: Filter): Int

The total number of tests that are expected to run when this <code>Suite</code>'s <code>run</code> method is invoked.

The total number of tests that are expected to run when this <code>Suite</code>'s <code>run</code> method is invoked.

Value Params
filter

a <code>Filter</code> with which to filter tests to count based on their tags

Inherited from
SuiteMixin
def nestedSuites: IndexedSeq[Suite]

An immutable <code>IndexedSeq</code> of this <code>SuiteMixin</code> object's nested <code>Suite</code>s. If this <code>SuiteMixin</code> contains no nested <code>Suite</code>s, this method returns an empty <code>IndexedSeq</code>.

An immutable <code>IndexedSeq</code> of this <code>SuiteMixin</code> object's nested <code>Suite</code>s. If this <code>SuiteMixin</code> contains no nested <code>Suite</code>s, this method returns an empty <code>IndexedSeq</code>.

Inherited from
SuiteMixin
def rerunner: Option[String]

The fully qualified name of the class that can be used to rerun this suite.

The fully qualified name of the class that can be used to rerun this suite.

Inherited from
SuiteMixin
def run(testName: Option[String], args: Args): Status

Runs this suite of tests.

Runs this suite of tests.

Value Params
args

the <code>Args</code> for this run

testName

an optional name of one test to execute. If <code>None</code>, all relevant tests should be executed. I.e., <code>None</code> acts like a wildcard that means execute all relevant tests in this <code>Suite</code>.

Returns

a <code>Status</code> object that indicates when all tests and nested suites started by this method have completed, and whether or not a failure occurred.

Throws
NullArgumentException

if any passed parameter is <code>null</code>.

Inherited from
SuiteMixin
protected def runNestedSuites(args: Args): Status

Runs zero to many of this suite's nested suites.

Runs zero to many of this suite's nested suites.

Value Params
args

the <code>Args</code> for this run

Returns

a <code>Status</code> object that indicates when all nested suites started by this method have completed, and whether or not a failure occurred.

Throws
NullArgumentException

if <code>args</code> is <code>null</code>.

Inherited from
SuiteMixin
protected def runTests(testName: Option[String], args: Args): Status

Runs zero to many of this suite's tests.

Runs zero to many of this suite's tests.

Value Params
args

the <code>Args</code> for this run

testName

an optional name of one test to run. If <code>None</code>, all relevant tests should be run. I.e., <code>None</code> acts like a wildcard that means run all relevant tests in this <code>Suite</code>.

Returns

a <code>Status</code> object that indicates when all tests started by this method have completed, and whether or not a failure occurred.

Throws
NullArgumentException

if either <code>testName</code> or <code>args</code> is <code>null</code>.

Inherited from
SuiteMixin
def startContainers(): Containers

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 suiteId: String

A string ID for this <code>Suite</code> that is intended to be unique among all suites reported during a run.

A string ID for this <code>Suite</code> that is intended to be unique among all suites reported during a run.

The suite ID is <em>intended</em> to be unique, because ScalaTest does not enforce that it is unique. If it is not unique, then you may not be able to uniquely identify a particular test of a particular suite. This ability is used, for example, to dynamically tag tests as having failed in the previous run when rerunning only failed tests.

Returns

this <code>Suite</code> object's ID.

Inherited from
SuiteMixin
def suiteName: String

A user-friendly suite name for this <code>Suite</code>.

A user-friendly suite name for this <code>Suite</code>.

This trait's implementation of this method returns the simple name of this object's class. This trait's implementation of <code>runNestedSuites</code> calls this method to obtain a name for <code>Report</code>s to pass to the <code>suiteStarting</code>, <code>suiteCompleted</code>, and <code>suiteAborted</code> methods of the <code>Reporter</code>.

Returns

this <code>Suite</code> object's suite name.

Inherited from
SuiteMixin
def tags: Map[String, Set[String]]

A <code>Map</code> whose keys are <code>String</code> names of tagged tests and whose associated values are the <code>Set</code> of tag names for the test. If a test has no associated tags, its name does not appear as a key in the returned <code>Map</code>. If this <code>Suite</code> contains no tests with tags, this method returns an empty <code>Map</code>.

A <code>Map</code> whose keys are <code>String</code> names of tagged tests and whose associated values are the <code>Set</code> of tag names for the test. If a test has no associated tags, its name does not appear as a key in the returned <code>Map</code>. If this <code>Suite</code> contains no tests with tags, this method returns an empty <code>Map</code>.

Subclasses may override this method to define and/or discover tags in a custom manner, but overriding method implementations should never return an empty <code>Set</code> as a value. If a test has no tags, its name should not appear as a key in the returned <code>Map</code>.

Inherited from
SuiteMixin
def testDataFor(testName: String, theConfigMap: ConfigMap): TestData

Provides a <code>TestData</code> instance for the passed test name, given the passed config map.

Provides a <code>TestData</code> instance for the passed test name, given the passed config map.

This method is used to obtain a <code>TestData</code> instance to pass to <code>withFixture(NoArgTest)</code> and <code>withFixture(OneArgTest)</code> and the <code>beforeEach</code> and <code>afterEach</code> methods of trait <code>BeforeAndAfterEach</code>.

Value Params
testName

the name of the test for which to return a <code>TestData</code> instance

theConfigMap

the config map to include in the returned <code>TestData</code>

Returns

a <code>TestData</code> instance for the specified test, which includes the specified config map

Inherited from
SuiteMixin
def testNames: Set[String]

A <code>Set</code> of test names. If this <code>Suite</code> contains no tests, this method returns an empty <code>Set</code>.

A <code>Set</code> of test names. If this <code>Suite</code> contains no tests, this method returns an empty <code>Set</code>.

Although subclass and subtrait implementations of this method may return a <code>Set</code> whose iterator produces <code>String</code> test names in a well-defined order, the contract of this method does not required a defined order. Subclasses are free to implement this method and return test names in either a defined or undefined order.

Inherited from
SuiteMixin
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:

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
}
Value Params
runTest

Test body

Inherited from
TestContainersSuite

Deprecated and Inherited fields

@deprecated("The styleName lifecycle method has been deprecated and will be removed in a future version of ScalaTest with no replacement.", "3.1.0")
val styleName: String

<strong>The <code>styleName</code> lifecycle method has been deprecated and will be removed in a future version of ScalaTest.</strong>

<strong>The <code>styleName</code> lifecycle method has been deprecated and will be removed in a future version of ScalaTest.</strong>

This method was used to support the chosen styles feature, which was deactivated in 3.1.0. The internal modularization of ScalaTest in 3.2.0 will replace chosen styles as the tool to encourage consistency across a project. We do not plan a replacement for <code>styleName</code>.

Deprecated
Inherited from
SuiteMixin

Implicits

Deprecated and Inherited implicits

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