The basic difference between all these annotations is as follows -
- @BeforeEach - Use to run a common code before( eg setUp) each test method
execution. analogous to JUnit 4’s @Before.
- @AfterEach - Use to run a common code after( eg tearDown) each test method execution. analogous to JUnit 4’s @After.
- @BeforeAll - Use to run once per class before any test execution. analogous to JUnit 4’s @BeforeClass.
- @AfterAll - Use to run once per class after all test are executed. analogous to JUnit 4’s @AfterClass.
All these annotations along with the usage is defined on Codingeek - Junit5 Test Lifecycle