This exercise helps you to understand how you can read your test data from a CSV file and pass the test data to a parameterized test. Let’s start by taking a quick look at the system under test.
The Calculator
class has a static
method called sum()
which returns the sum of two long
values given as method parameters. The source code of the Calculator
class looks as follows:
public class Calculator { public static long sum(long a, long b) { return a + b; } }
During this exercise you will create the test data that’s passed to a parameterized test method which ensures that the sum()
method of the Calculator
class is working as expected. You can finish this exercise by following these steps:
1. Open the CalculatorTest
class that’s found from the com.cleantestautomation.junit5intro
package.
2. Create the CSV file which contains the test data that’s passed to the shouldReturnCorrectSum()
method.
3. Ensure that JUnit 5 reads the test data from the created CSV file when it runs your parameterized test method.
4. Run your parameterized test and make sure that all test invocations pass.