Answer the question
In order to leave comments, you need to log in
How to run single tests in descendants (JUnit 5)?
There are two programs with similar functionality.
One is a more advanced version of the second, if we draw an analogy with a calculator - the first can + -
and the second + - * /
.
Both need to be tested.
There is a class of JUnit tests: conditionally, TestFirstProgram.
All by the same analogy with a calculator, it is arranged somehow like this:
public class ТестыПервойПрограммы {
protected тестПосчитать(ожидаемыйРезультат, выражение) {
assertEquals(ожидаемыйРезультат, new ПерваяПрограмма().посчитать(выражение));
}
@Test
void дваПлюсДва() {
тестПосчитать(4, "2+2");
}
}
public class ТестыВторойПрограммы extends ТестыПервойПрограммы {
@Override
protected тестПосчитать(ожидаемыйРезультат, выражение) {
assertEquals(ожидаемыйРезультат, new ВтораяПрограмма().посчитать(выражение));
}
@Test
void дваУмножитьНаПять() {
тестПосчитать(10, "2*5");
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question