Issue
@BeforeAll and @AfterAll have to be static. So I can't use JdbcTemplate. How should I empty the database?
I have now initialized the data in a method with @PostConstruct. But I couldn't find a working counterpart. I had thought about adding a counter to @AfterEach and deleting the database at the last execution. But this is not a very nice workaround.
Solution
@AfterClass
in JUnit 4 required the annotated method to be static
. So there's no difference: if you could use @AfterClass
in JUnit 4, you can still use @AfterAll
in JUnit Jupiter.
The difference, however, is that JUnit Jupiter allows @AfterAll
-annotated methods not to be static. See the documentation for how to allow that.
Answered By - JB Nizet