code described in the question:
https://stackoverflow.com/questions/68830293/how-to-substitute-csvsourcefile-in-parent-abstracttest-to-use-different-file-so
This is how I would organized those tests. Either one single dedicated suite for all the properties (personally I would prefer this approach): class PropertiesValuesTest { @ParameterizedTest @ArgumentsSource(PropsNumbers.class) void testProperty(Property prop, BigInt number, boolean exp) { var actual = prop.test(number); assertThat(actual).isEqualTo(exp); } static class PropsNumbers implements ArugmentsProvider { List<Argument> provide() { return List.of( // prop type, prop value, expected ??? Argument.of(new Jumping(), 100, true), Argument.of(new Jumping(), 200, false), // ..... ); } } } And if you ask if I prefer to not put test input params and expected values in a separate file - YES. Those separate files make reader to jump like a crazy across the file tree and glue it all back together to understand what are the requirements. Or another option - in case if I wanted this test case to be inherited by all specific property unit tests, then: abstract class PropertyTest<T extends Property> { protected abstract T propertyToBeTested(); protected abstract List<Pair<BigInteger, Boolean>> testValues(); @Test void testProperty() { var prop = propertyToBeTested(); testValues().forEach(number, exp -> { var actual = prop.test(number); assertThat(actual).isEqualTo(exp); }); } Even though annotations for data driven tests look sexy, those have limitations, same ones like any other java annotation. All annotation parameters must be known at compile time. There are ways to overcome this, but junit5 devs didn't used those. So you can't parameterize those annotations with something that will be defined by the subclass.
Обсуждают сегодня