Using Life Cycle Callback Extensions

Life cycle callback extensions allow us to run the code during the life cycle phase of a test.

The following are the different phases that comprise the life cycle of a JUnit Test.

  • BeforeAll
  • BeforeEach
  • Test Method
  • AfterEach
  • AfterAll

Jupiter provides an extension interface for each of the above mentioned test life cycle stages:

  • BeforeAllCallback is executed before the @BeforeAll method.

  • AfterAllCallback is executed after the @AfterAll method.

  • BeforeEachCallback is executed before the @BeforeEach method.

  • BeforeTestExecutionCallback is executed before the test method execution.

  • AfterTestExecutionCallback is executed after the test method execution.

  • AfterEachCallback is executed after the @AfterEach method.

Get hands-on with 1200+ tech skills courses.