Exercise: Create a Test Class With JUnit 5

This exercise helps you understand how you can create a new test class with JUnit 5 and add setup, teardown, and test methods to the created class. Also, after you have finished this exercise, you understand the invocation order of setup, teardown, and test methods. You can finish this exercise by following these steps:

1. Clone the Git repository that contains the sample applications of this course. If you have already cloned that repository, you can ignore this step.

2. Open the project found from the introduction-to-junit5/introduction-to-junit5-test-classes/exercises/test-class-exercise directory with your favorite IDE.

3. Create a new test class to the com.cleantestautomation.junit5intro package. Don’t add a display name to the created test class.

4. Write a setup method that’s invoked once before the test methods are run. Implement this method by writing a unique id to the System.out.

5. Write a setup method that’s invoked before a test method is run. Implement this method by writing a unique id to the System.out.

6. Write two test methods which write unique ids to the System.out. Don’t add display names to these test methods.

7. Write a teardown method that’s invoked after a test method has been run. Implement this method by writing a unique id to the System.out.

8. Write a teardown method that’s invoked once after all test methods have been run. Implement this method by writing a unique id to the System.out.

9. Run your tests With Maven or Gradle and verify that the setup, teardown, and test methods are run in the expected order.

10. Run your tests with your IDE and take a screenshot of the test report that’s displayed by your IDE.

11. Add a proper display name to your test class and specify the display names of your test methods.

12. Run your tests with your IDE and take a screenshot of the test report that’s displayed by your IDE.

13. Compare these screenshots with each other and try to spot the difference.