Exercise: Write a Simple Parameterized Test

This exercise helps you to understand the basics of parameterized tests. After you have finished this exercise, you can add parameterized test methods to your test classes, you understand how you can pass one argument to your parameterized test, and you can configure the display name of each test method invocation. 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 skip this step.

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

3. Add a new test class to the com.cleantestautomation.junit5intro package and configure its display name.

4. Add a new parameterized test to your test class and configure its display name. Don’t configure the display name of each test method invocation.

5. Add one method parameter (message) to your parameterized test. Set the type of this method parameter to String.

6. Write an assertion which ensures that the argument, which was passed to your parameterized test, isn’t blank. You can use this assertion:

assertThat(message).isNotBlank();

Remember to add this static import to your test class or your code won’t compile:

import static org.assertj.core.api.Assertions.assertThat;

7. Configure the test data that’s passed to your parameterized test. Make sure that three messages are passed to your parameterized test method.

8. Run your tests with your IDE and take a screenshot of the test report.

9. Configure the display name of each test method invocation. Use the format: ‘The message: [argument] shouldn’t be blank’.

9. Run your tests with your IDE and take a screenshot of the test report.

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