use of org.junit.jupiter.api.DynamicTest in project robozonky by RoboZonky.
the class InvestorTest method forPossibility.
private DynamicNode forPossibility(final ProxyType proxyType, final Captcha captcha, final Remote confirmation, final RemoteResponse confirmationResponse, final ZonkyResponseType responseType) {
final RecommendedLoan recommendedLoan = getRecommendation(confirmation, captcha);
final DynamicTest seenBefore = dynamicTest("seen before", () -> testBeforeSeen(proxyType, confirmationResponse, responseType, recommendedLoan));
final DynamicTest notSeenBefore = dynamicTest("never seen", () -> testNeverSeen(proxyType, confirmationResponse, responseType, recommendedLoan));
final Stream<DynamicTest> tests = isValidForLoansSeenBefore(responseType) ? Stream.of(seenBefore, notSeenBefore) : Stream.of(notSeenBefore);
final String containerName = proxyType + "+" + captcha + "+" + confirmation + "+" + confirmation + "=" + responseType;
return dynamicContainer(containerName, tests);
}
use of org.junit.jupiter.api.DynamicTest in project mssql-jdbc by Microsoft.
the class lobsTest method executeDynamicTests.
@TestFactory
public Collection<DynamicTest> executeDynamicTests() {
List<Class> classes = new ArrayList<Class>(Arrays.asList(Blob.class, Clob.class, DBBinaryStream.class, DBCharacterStream.class));
List<Boolean> isResultSetTypes = new ArrayList<>(Arrays.asList(true, false));
Collection<DynamicTest> dynamicTests = new ArrayList<>();
for (Class aClass : classes) {
for (Boolean isResultSetType : isResultSetTypes) {
final Class lobClass = aClass;
final boolean isResultSet = isResultSetType;
Executable exec = new Executable() {
@Override
public void execute() throws Throwable {
testInvalidLobs(lobClass, isResultSet);
}
};
// create a test display name
String testName = " Test: " + lobClass + (isResultSet ? " isResultSet" : " isPreparedStatement");
// create dynamic test
DynamicTest dTest = DynamicTest.dynamicTest(testName, exec);
// add the dynamic test to collection
dynamicTests.add(dTest);
}
}
return dynamicTests;
}
use of org.junit.jupiter.api.DynamicTest in project junit5 by junit-team.
the class TestFactoryTestDescriptor method createDynamicDescriptor.
static Optional<JupiterTestDescriptor> createDynamicDescriptor(JupiterTestDescriptor parent, DynamicNode node, int index, TestSource source, DynamicDescendantFilter dynamicDescendantFilter) {
UniqueId uniqueId;
Supplier<JupiterTestDescriptor> descriptorCreator;
if (node instanceof DynamicTest) {
DynamicTest test = (DynamicTest) node;
uniqueId = parent.getUniqueId().append(DYNAMIC_TEST_SEGMENT_TYPE, "#" + index);
descriptorCreator = () -> new DynamicTestTestDescriptor(uniqueId, index, test, source);
} else {
DynamicContainer container = (DynamicContainer) node;
uniqueId = parent.getUniqueId().append(DYNAMIC_CONTAINER_SEGMENT_TYPE, "#" + index);
descriptorCreator = () -> new DynamicContainerTestDescriptor(uniqueId, index, container, source, dynamicDescendantFilter);
}
if (dynamicDescendantFilter.test(uniqueId)) {
JupiterTestDescriptor descriptor = descriptorCreator.get();
parent.addChild(descriptor);
return Optional.of(descriptor);
}
return Optional.empty();
}
use of org.junit.jupiter.api.DynamicTest 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;
}
use of org.junit.jupiter.api.DynamicTest in project junit5 by junit-team.
the class TestClassWithTemplate method resolvingDynamicTestByUniqueIdAndTestFactoryByMethodSelectorResolvesTestFactory.
@Test
void resolvingDynamicTestByUniqueIdAndTestFactoryByMethodSelectorResolvesTestFactory() {
Class<?> clazz = MyTestClass.class;
UniqueId factoryUid = uniqueIdForTestFactoryMethod(clazz, "dynamicTest()");
UniqueId dynamicTestUid = factoryUid.append(DYNAMIC_TEST_SEGMENT_TYPE, "#1");
LauncherDiscoveryRequest request = //
request().selectors(selectUniqueId(dynamicTestUid), //
selectMethod(clazz, "dynamicTest")).build();
resolver.resolveSelectors(request, engineDescriptor);
assertThat(engineDescriptor.getDescendants()).hasSize(2);
assertThat(uniqueIds()).containsSequence(uniqueIdForClass(clazz), factoryUid);
TestDescriptor testClassDescriptor = getOnlyElement(engineDescriptor.getChildren());
TestDescriptor testFactoryDescriptor = getOnlyElement(testClassDescriptor.getChildren());
DynamicDescendantFilter dynamicDescendantFilter = getDynamicDescendantFilter(testFactoryDescriptor);
assertThat(dynamicDescendantFilter.test(UniqueId.root("foo", "bar"))).isTrue();
}
Aggregations