Parameterized tests
On This Lesson 4 topics
This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.
In this lesson
run one test body against many inputs.
Planned topics
@ParameterizedTestreplaces copy-pasted tests that differ only in data.@ValueSourcefor a list of single values.@CsvSourcefor several columns per row (input and expected result).@MethodSourcefor complex objects built in a static method.- Use
{0}-style placeholders in thenameattribute so failures say which row broke.
Draft outline details
Demonstration
@ParameterizedTest(name = "{0}% off {1} = {2}")
@CsvSource({"10,100.00,90.00", "0,100.00,100.00", "50,80.00,40.00"})
void discountTable(int pct, BigDecimal price, BigDecimal expected) {
assertEquals(0, expected.compareTo(calc.discounted(price, pct)));
}Check your understanding
Which source fits a table of input/expected pairs?
Show answer
@CsvSource.
Practice
Apply this lesson with the module's lab, exercises and quiz.
Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.