Похожие чаты

Who know JUnit 5? How can I eliminate the duplicate

code described in the question:

https://stackoverflow.com/questions/68830293/how-to-substitute-csvsourcefile-in-parent-abstracttest-to-use-different-file-so

3 ответов

27 просмотров

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.

Похожие вопросы

Обсуждают сегодня

Господа, а что сейчас вообще с рынком труда на делфи происходит? Какова ситуация?
Rꙮman Yankꙮvsky
29
А вообще, что может смущать в самой Julia - бы сказал, что нет единого стандартного подхода по многим моментам, поэтому многое выглядит как "хаки" и произвол. Короче говоря, с...
Viktor G.
2
@Benzenoid can you tell me the easiest, and safest way to bu.y HEX now?
Živa Žena
20
This is a question from my wife who make a fortune with memes 😂😂 About the Migration and Tokens: 1. How will the old tokens be migrated to the new $LGCYX network? What is th...
🍿 °anton°
2
30500 за редактор? )
Владимир
47
а через ESC-код ?
Alexey Kulakov
29
What is the Dex situation? Agora team started with the Pnetwork for their dex which helped them both with integration. It’s completed but as you can see from the Pnetwork ann...
Ben
1
Гайс, вопрос для разносторонее развитых: читаю стрим с юарта, нада выделять с него фреймы с определенной структурой, если ли чо готовое, или долбаться с ринг буффером? нада у...
Vitaly
9
Anyone knows where there are some instructions or discort about failed bridge transactions ?
Jochem
21
@lozuk how do I get my phex copies of my ehex from a atomic wallet, to move to my rabby?
Justfrontin 👀
11
Карта сайта