Description
openedon Jun 30, 2016
As it stands the creation of dynamic tests via test factory methods is, from a coding experience perspective, no improvement over simple looping:
// should be executed for different points and distances
void testDistanceComputation(Point p1, Point p2, double distance) {
assertEquals(distance, p1.distanceTo(p2));
}
@Test
void testDistanceComputations() {
createTestData().forEach(testData ->
testDistanceComputation(datum.point1(), datum.point2(), datum.distance()));
}
}
@TestFactory
Stream<DynamicTest> testDistanceComputations() {
return DynamicTest.stream(
createTestData(),
datum -> "Testing " + datum,
datum -> testDistanceComputation(datum.point1(), datum.point2(), datum.distance()));
}
I see a couple of ways in which extensions could improve this situation but for that an extension point for dynamic test generation is needed.
My intuition is to create an extension interface, whose implementations must be registered on the test class and would be called at exactly the same point where @TestFactory
is resolved now. They would have to return a stream of dynamic tests, which were then processed like those of test factories. Ideally @TestFactory
would use the same mechanism.
This should give extensions plenty of room to create tests, especially parameterized ones, much more conveniently.