Understanding JUnit 5 Life Cycle
Understand the life cycle of a unit test in JUnit 5.
Each JUnit5 test follows a life cycle where it goes through different phases.
The following are the three phases involved as parts of the test life cycle:
- Setup
- Execution
- Cleanup
-
Setup: The test infrastructure and the required configuration is prepared. This setup is prepared at two levels.
- The first one is at the class level where we can setup/configure a resource like a Database Connection and insert required Test Data into the database. This phase runs only once per Test class.
- The second one is at the test level, where we initialize the required objects for the test execution. This allows us to remove duplicated code inside the tests. This phase runs before every test method.
-
Execution: The tests are executed and verified. We mark the test as a success or a failure based on this.
-
Cleanup: We have the below ...