0

How prevent @AfterTest execution in @BeforeEach? Throwing an exception in @BeforeEach does not help: @AfterEach will execute anyway.

1 Answer 1

1

It’s the purpose of methods annotated with @AfterEach to be called regardless of what happens in a test. That’s why you cannot and should not prevent it. If you have the need to execute clean up code on a case by case basis you have several options:

  • Structure your tests differently, eg using nested tests
  • Make the after-each code more robust so that it can run anyway
  • Run the after code directly in those tests where it applies
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.