2

We've encountered a problem which we have few test classes, each one of them has it's own @BeforeClass logic. We want that in case we run tests from suite, Test's @AfterClass won't be executed as it will cause a conflict with the suite @AfterClass.

(In our case, we are running a docker container in @BeforeClass and kill it in @AfterClass of each test class. But once we run tests through suite, we want this opearation will be executed only once in suite before and after class).

We know that we can a set a system property in suite @BeforeClass (and to check it in before class of test classes) but we wonder if there is some built in solution for our problem?

Thanks a lot.

roh
  • 123
  • 1
  • 1
  • 10
  • 1
    For such integration test, i would rather choose a JUnit Rule instead of Before(Class) Annotions to init environments such as docker. This might help you [integration-tests-with-a-docker-junit-rule](https://geowarin.github.io/integration-tests-with-a-docker-junit-rule/) – Andre Albert Feb 27 '18 at 16:27
  • 1
    Have a look at using a custom RunListener: https://stackoverflow.com/a/14757266/2210137 – msfoster Feb 27 '18 at 16:32

0 Answers0