Package

com.dimafeng.testcontainers

scalatest

Permalink

package scalatest

Visibility
  1. Public
  2. All

Type Members

  1. case class IllegalWithContainersCall() extends IllegalStateException with Product with Serializable

    Permalink
  2. trait TestContainerForAll extends TestContainersForAll

    Permalink

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

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

    Example:

    class MysqlSpec extends FlatSpec 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
      it should "test" in withContainers { mysqlContainer =>
        // Inside your test body you can do with your container whatever you want to
        assert(mysqlContainer.jdbcUrl.nonEmpty)
      }
    }
  3. trait TestContainerForEach extends TestContainersForEach

    Permalink

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

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

    Example:

    class MysqlSpec extends FlatSpec 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
      it should "test" in withContainers { mysqlContainer =>
        // Inside your test body you can do with your container whatever you want to
        assert(mysqlContainer.jdbcUrl.nonEmpty)
      }
    }
  4. trait TestContainersForAll extends TestContainersSuite

    Permalink

    Starts containers before all tests and stop then after all tests

    Starts containers before all tests and stop then after all tests

    Example:

    class ExampleSpec extends FlatSpec 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)
      }
    
    }
  5. trait TestContainersForEach extends TestContainersSuite

    Permalink

    Starts containers before each test and stop them after each test

    Starts containers before each test and stop them after each test

    Example:

    class ExampleSpec extends FlatSpec 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)
      }
    
    }

Ungrouped