Version Matrix

Testcontainers for ZIO

CI Release
Build Status Release Artifacts Release Artifacts Release Artifacts

Provides idiomatic, easy-to-use ZLayers for Testcontainers-scala.

Testcontainers Best-Practices

  • Make sure your test configuration has the following settings Test / fork := true. Without this the Docker container created by the test will NOT be cleaned up until you exit SBT/the JVM process. This could quickly run your machine out of resources as you will end up with a ton of orphaned containers running.
  • Use provideLayerShared({container}.live) on your suite so that each test case isn't spinning up and down the container.

MySQL

Provides a managed ZLayer that starts and stops a com.dimafeng.testcontainers.MySQLTestContainer as well as also provding a managed java.sql.Connection.

libraryDependencies += "io.github.scottweaver" %% "zio-testcontainers-mysql" % "0.2.0"

See test cases for example usage.

Kafka

Provides a managed ZLayer that starts and stops a com.dimafeng.testcontainers.KafkaContainer.

You also have easy access to:

  • zio.kafka.consumer.ConsumerSettings via ZKafkaContainer.defaultConsumerSettings.
  • zio.kafka.consumer.ProducerSettings via ZKafkaContainer.defaultProducerSettings.

You can use these to create a zio.kafka.consumer.Consumer and/or zio.kafka.producer.Producer that can be used to interact with the Kafka container instance.

libraryDependencies += "io.github.scottweaver" %% "zio-testcontainers-kafka" % "0.2.0"

See test cases for example usage.

Database Migrations Aspect

Not really a test container, useful none the less.

The io.github.scottweaver.zio.aspect.DatabaseMigrationsAspect provides a ZIO TestAspect for running database migrations via Flyway. It seemlessly integrates with the ZMySQLContainer by using the io.github.scottweaver.zio.models.JdbcInfo provided by ZMySQLContainer.live to run your migrations.

If you are not using ZMySQLContainer you can just manually provide an appropriate JdbcInfo as a ZLayer to your tests that are using the DbMigrationAspect.

libraryDependencies += "io.github.scottweaver" %% "db-migration-aspect" % "0.2.0"

References