TestContainersForAll
Starts containers before all tests and stop then after all tests
Example:
class ExampleSpec extends AnyFlatSpec 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:
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)
}
}
Type members
Inherited types
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
Inherited methods
Override, if you want to do something after containers start.
Override, if you want to do something after containers start.
- Inherited from
- TestContainersSuite
Override, if you want to do something before containers stop.
Override, if you want to do something before containers stop.
- Inherited from
- TestContainersSuite
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
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
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
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
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
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
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
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
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
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
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
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
<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