Search in sources :

Example 16 with DynamicTest

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);
}
Also used : RecommendedLoan(com.github.robozonky.api.strategies.RecommendedLoan) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 17 with DynamicTest

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;
}
Also used : DBCharacterStream(com.microsoft.sqlserver.testframework.Utils.DBCharacterStream) Blob(java.sql.Blob) DBBinaryStream(com.microsoft.sqlserver.testframework.Utils.DBBinaryStream) ArrayList(java.util.ArrayList) DynamicTest(org.junit.jupiter.api.DynamicTest) NClob(java.sql.NClob) Clob(java.sql.Clob) Executable(org.junit.jupiter.api.function.Executable) TestFactory(org.junit.jupiter.api.TestFactory)

Example 18 with DynamicTest

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();
}
Also used : UniqueId(org.junit.platform.engine.UniqueId) DynamicContainer(org.junit.jupiter.api.DynamicContainer) DynamicTest(org.junit.jupiter.api.DynamicTest)

Example 19 with DynamicTest

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;
}
Also used : ArrayList(java.util.ArrayList) Method(java.lang.reflect.Method) DynamicTest(org.junit.jupiter.api.DynamicTest) Details(org.junit.platform.console.options.Details) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest) Theme(org.junit.platform.console.options.Theme) DynamicNode(org.junit.jupiter.api.DynamicNode) ArrayList(java.util.ArrayList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) EnumMap(java.util.EnumMap)

Example 20 with DynamicTest

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();
}
Also used : DiscoverySelectors.selectUniqueId(org.junit.platform.engine.discovery.DiscoverySelectors.selectUniqueId) UniqueId(org.junit.platform.engine.UniqueId) LauncherDiscoveryRequest(org.junit.platform.launcher.LauncherDiscoveryRequest) DynamicDescendantFilter(org.junit.jupiter.engine.descriptor.DynamicDescendantFilter) TestDescriptor(org.junit.platform.engine.TestDescriptor) TestTemplateInvocationTestDescriptor(org.junit.jupiter.engine.descriptor.TestTemplateInvocationTestDescriptor) JupiterTestDescriptor(org.junit.jupiter.engine.descriptor.JupiterTestDescriptor) Test(org.junit.jupiter.api.Test) DynamicTest(org.junit.jupiter.api.DynamicTest)

Aggregations

DynamicTest (org.junit.jupiter.api.DynamicTest)25 Test (org.junit.jupiter.api.Test)16 TestFactory (org.junit.jupiter.api.TestFactory)14 Stream (java.util.stream.Stream)10 RecommendedLoan (com.github.robozonky.api.strategies.RecommendedLoan)7 DynamicTest.dynamicTest (org.junit.jupiter.api.DynamicTest.dynamicTest)7 ReturnCode (com.github.robozonky.api.ReturnCode)6 Event (com.github.robozonky.api.notifications.Event)6 EventListener (com.github.robozonky.api.notifications.EventListener)6 EventListenerSupplier (com.github.robozonky.api.notifications.EventListenerSupplier)6 ExecutionCompletedEvent (com.github.robozonky.api.notifications.ExecutionCompletedEvent)6 InvestmentDelegatedEvent (com.github.robozonky.api.notifications.InvestmentDelegatedEvent)6 InvestmentMadeEvent (com.github.robozonky.api.notifications.InvestmentMadeEvent)6 InvestmentPurchasedEvent (com.github.robozonky.api.notifications.InvestmentPurchasedEvent)6 InvestmentRejectedEvent (com.github.robozonky.api.notifications.InvestmentRejectedEvent)6 PurchasingCompletedEvent (com.github.robozonky.api.notifications.PurchasingCompletedEvent)6 PurchasingStartedEvent (com.github.robozonky.api.notifications.PurchasingStartedEvent)6 RoboZonkyEndingEvent (com.github.robozonky.api.notifications.RoboZonkyEndingEvent)6 SaleOfferedEvent (com.github.robozonky.api.notifications.SaleOfferedEvent)6 SellingCompletedEvent (com.github.robozonky.api.notifications.SellingCompletedEvent)6