mibutec
mibutec

Reputation: 2997

Test Discovery of Dynamic Tests in Eclipse Slow

Having a test class like this

public class VerySimpleFactory {
    @TestFactory
    public Stream<? extends DynamicNode> someTests() {
        DynamicContainer container1 = DynamicContainer.dynamicContainer("A",
                Arrays.asList(t("A1"), t("A2"), t("A3"), t("A4"), t("A5")));
        DynamicContainer container2 = DynamicContainer.dynamicContainer("B",
                Arrays.asList(t("B1"), t("B2"), t("B3"), t("B4"), t("B5")));
        DynamicContainer container3 = DynamicContainer.dynamicContainer("C",
                Arrays.asList(t("C1"), t("C2"), t("C3"), t("C4"), t("C5")));
        DynamicContainer container4 = DynamicContainer.dynamicContainer("D",
                Arrays.asList(t("D1"), t("D2"), t("D3"), t("D4"), t("D5")));

        return Arrays.asList(container1, container2, container3, container4).stream();
    }

    @Test
    public void t1() throws Exception {
        Thread.sleep(1000);
    }

    @Test
    public void t2() throws Exception {
        Thread.sleep(1000);
    }

    public DynamicTest t(String name) {
        return DynamicTest.dynamicTest(name, () -> Thread.sleep(1000));
    }
}

the Tests having a @Test annotaiton are discovered instantly by JUnit View, but the tests from TestFactory are discoverd at runtime, each after the last test was completely executed. This leads to a changing and "jumping" JUnit view. Also I cannot select a special test I'm interested in to be executed as single test, until all previous tests were executed.

It would be much nicer if all dynamic tests were shown in JUnit view also at beginning of test execution.

If this doesn't happen, is it a problem of JUnit 5, eclipse or my code?

Upvotes: 0

Views: 138

Answers (1)

Sormuras
Sormuras

Reputation: 9069

Dynamic tests are dynamic. Not static.

It is not possible to know before-hand which and how many tests will be generated by @TestFactory annotated method ... actually, it may produce tests in an eternal loop.

Copied from https://junit.org/junit5/docs/current/user-guide/#writing-tests-dynamic-tests-examples

generateRandomNumberOfTests() implements an Iterator that generates random numbers, a display name generator, and a test executor and then provides all three to DynamicTest.stream(). Although the non-deterministic behavior of generateRandomNumberOfTests() is of course in conflict with test repeatability and should thus be used with care, it serves to demonstrate the expressiveness and power of dynamic tests.

Upvotes: 3

Related Questions