Skip to content

StefanHufschmidt/TestcontainersJUnit5ParallelExample

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Testcontainers JUnit 5 parallel example

This example shows a possible configuration to use Testcontainers for parallel test execution with JUnit 5. Running tests in parallel requires clean test contexts for all parallel running tests. To ensure having clean containers for the specific use case we're using some JUnit5 extensions in combination with self defined annotations.

Component explanation

  • FreshContainersPerTestClass Annotation to use when require a fresh container for each test class. Not all test classes require a complete fresh container setup for each method.
  • FreshContainersPerTestMethod Annotation to use when require a fresh container for each test method. At some test classes we require a complete fresh container setup for each method to avoid test pollution.
  • ContainerHolderParameterResolver Resolves the parameter for the ContainerHolder used within the specific test context.
  • ContainerHolder A holder object to store all your required Testcontainers at. In this example we're only using one MockServerContainer but this could basically contain your whole setup.

Configure parallelism

On systems where you'll execute your tests you'll not find infinite resources. Since you're spinning up several containers in parallel when running your tests in parallel you might use more resources than regularly. Therefore, a good configuration is recommended. You can define the amount of parallel test executions by configuring the property junit.jupiter.execution.parallel.config.fixed.parallelism inside your junit-platform.properties.

About

Testcontainers JUnit5 parallelism example

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages