use of org.junit.jupiter.api.DynamicNode in project junit5 by junit-team.
the class TestFactoryTestDescriptor method invokeTestMethod.
// --- Node ----------------------------------------------------------------
@Override
protected void invokeTestMethod(JupiterEngineExecutionContext context, DynamicTestExecutor dynamicTestExecutor) {
ExtensionContext extensionContext = context.getExtensionContext();
context.getThrowableCollector().execute(() -> {
Object instance = extensionContext.getRequiredTestInstance();
Object testFactoryMethodResult = executableInvoker.invoke(getTestMethod(), instance, extensionContext, context.getExtensionRegistry());
TestSource source = getSource().orElseThrow(() -> new JUnitException("Illegal state: TestSource must be present"));
try (Stream<DynamicNode> dynamicNodeStream = toDynamicNodeStream(testFactoryMethodResult)) {
int index = 1;
Iterator<DynamicNode> iterator = dynamicNodeStream.iterator();
while (iterator.hasNext()) {
DynamicNode dynamicNode = iterator.next();
Optional<JupiterTestDescriptor> descriptor = createDynamicDescriptor(this, dynamicNode, index++, source, getDynamicDescendantFilter());
descriptor.ifPresent(dynamicTestExecutor::execute);
}
} catch (ClassCastException ex) {
throw invalidReturnTypeException(ex);
}
});
}
use of org.junit.jupiter.api.DynamicNode in project junit5 by junit-team.
the class ConsoleDetailsTests method scanContainerClassAndCreateDynamicTests.
private List<DynamicNode> scanContainerClassAndCreateDynamicTests(Class<?> containerClass) {
String containerName = containerClass.getSimpleName().replace("TestCase", "");
// String containerName = containerClass.getSimpleName();
List<DynamicNode> nodes = new ArrayList<>();
Map<Details, List<DynamicTest>> map = new EnumMap<>(Details.class);
for (Method method : findMethods(containerClass, m -> m.isAnnotationPresent(Test.class))) {
String methodName = method.getName();
Class<?>[] types = method.getParameterTypes();
for (Details details : Details.values()) {
List<DynamicTest> tests = map.computeIfAbsent(details, key -> new ArrayList<>());
for (Theme theme : Theme.values()) {
String caption = containerName + "-" + methodName + "-" + details + "-" + theme;
String[] args = { //
"--include-engine", //
"junit-jupiter", //
"--details", //
details.name(), //
"--details-theme", //
theme.name(), //
"--disable-ansi-colors", //
"true", //
"--include-classname", //
containerClass.getCanonicalName(), //
"--select-method", //
getFullyQualifiedMethodName(containerClass, methodName, types) };
String displayName = methodName + "() " + theme.name();
String dirName = "console/details/" + containerName.toLowerCase();
String outName = caption + ".out.txt";
tests.add(DynamicTest.dynamicTest(displayName, new Runner(dirName, outName, args)));
}
}
}
map.forEach((details, tests) -> nodes.add(DynamicContainer.dynamicContainer(details.name(), tests)));
return nodes;
}
Aggregations