Performing parameterized testing
This leaves one more type of testing to look at, a parameterized test. As you may have realized, if you want to run a test to determine whether the result is accurate for several values, then you will need one method per set of values. JUnit 5 simplifies this task by allowing you to create a list of values. Let’s see how this works. Here is the new parameterized test class:
public class ParameterizedTests { private Calculation calc; private FinancialData data;
We will not instantiate the FinancialData
object here as we did in the previous example. It will be created by a private helper method:
@BeforeEach public void init() { calc = new Calculation(); }
The first annotation declares that this will be a parameterized test. This means that this method will be run once...