JUnit 5 пропускать кейсы до их начала
Есть ли возможность в JUnit 5 выполнить проверку кейса в списке, перед выполнением. Т.е. если он присутствует в списке - то запускать, в примере ниже дожен запуститься только firstCase
List<String> checkList = new ArrayList<>() {{
add("firstCase");
}};
@BeforeEach
void checkInList(TestInfo testInfo) {
String methodName = testInfo.getTestMethod().orElseThrow().getName();
if (checkList.contains(methodName)) {
startCase!
}
}
@Test
public void firstCase() {
System.out.println("tra ta ta");
}
@Test
public void secondCase() {
System.out.println("tra ta ta 2");
}
Ответы (1 шт):
Автор решения: LexPlutor
→ Ссылка
Помогло ExecutionCondition, создал класс RunMethodCondition, зарегистрировал при помощи аннотации @ExtendWith(RunMethodCondition.class), в классе переопределил метод evaluateExecutionCondition в котором проверял наличие кейса в списке
public class RunMethodCondition implements ExecutionCondition {
private final ListCases listCases = new ListCases();
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context){
final Method testedMethod = context.getTestMethod().get();
if (listCases.listKeyCases.contains(testedMethod.getName())) {
return ConditionEvaluationResult.enabled("enabled");
}
return ConditionEvaluationResult.disabled("disabled");
}
}
@Test
@ExtendWith(RunMethodCondition.class)
public void secondCase() {
System.out.println("secondCase");
}
@Test
@ExtendWith(RunMethodCondition.class)
public void secondCase2() {
System.out.println("secondCase2");
}