0

I'm using Maven pre-integration-tests and post-integration tests to setup and tear down a test environment with three services (say A, B and C)

Is it possible using Test containers to restart one of those services before a test? If not, can I do that using other docker library for Java?

Thanks!

italktothewind
  • 1,950
  • 2
  • 28
  • 55

1 Answers1

0

If your test is something similar to this.

@Container
public GenericContainer container = new GenericContainer(...);

You can use junit5 BeforeEach and AfterEach annotations to restart your containers before/after running your tests cases.

@BeforeEach
public void beforeEach() {
  container.start();
}

@AfterEach
public void afterEach() {
  container.stop();
}

If you need to restart the container only before specific test, you can try reorganizing your test methods using @Nested annotation

usuario
  • 2,132
  • 1
  • 10
  • 26