TestFactory

With the additional annotation @TestFactory you can use TableData as an easy-to-read source of similar but independent tests where each row is treated as its own test, optionally with a descriptive label.Here are some examples of parameterized tests with and without labels: Groovy @TestFactory def "individual tests use generated display labels"() { ["price" | "quantity" | "outcome"] { _________________________________ 10.0 | 30 | 300.0 -10.0 | 30 | -300.0 }.test { PriceCalculator.calculate(price, quantity).should == outcome } } @TestFactory def "individual tests label to clarify the use case"() { ["label" | "price" | "quantity" | "outcome"] { _____________________________________________________ "positive price" | 10.0 | 30 | 300.0 "negative price" | -10.0 | 30 | -300.0 }.test { PriceCalculator.calculate(price, quantity).should == outcome } } Java @TestFactory public Stream<DynamicTest> individualTestsUseGeneratedDisplayLabels() { TableData useCases = table("price", "quantity", "outcome", ______________________________, 10.0 , 30, 300.0, -10.0 , 30, -300.0); return DynamicTests.fromTable(useCases, r -> { double price = r.get("price"); int quantity = r.get("quantity"); double outcome = r.get("outcome"); actual(PriceCalculator.calculate(price, quantity)).should(equal(outcome)); }); } @TestFactory public Stream<DynamicTest> individualTestsLabelToClarifyUseCase() { TableData useCases = table("label" , "price", "quantity", "outcome", _________________________________________________, "positive price", 10.0 , 30, 300.0, "negative price", -10.0 , 30, -300.0); return DynamicTests.fromTable(useCases, r -> { double price = r.get("price"); int quantity = r.get("quantity"); double outcome = r.get("outcome"); actual(PriceCalculator.calculate(price, quantity)).should(equal(outcome)); }); }