Skip to content

JUnit Platform Surefire provider ignores purely dynamic test classes #384

Closed
@littleclay

Description

@littleclay

I have a test project I am running some JUnit 5 experiments with using the maven surefire plugin. I am seeing an issue with dynamic tests. It apparently isn't discovering TestFactories as tests unless regular test methods also appear in the class. Take the following test class:

import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
import java.util.stream.Stream;

public class FooTest {
    @Test
    public void foo() {
        System.out.println( "Hello" );
    }

    @TestFactory
    public Stream< DynamicTest > testFactoryFoo() {
        return Stream.of( "A", "B" )
                     .map( str -> DynamicTest.dynamicTest( "testFactoryFoo" + str + "()",
                                                           () -> System.out.println( str ) ) );
    }
}

If I run the command mvn clean test then I see the expected output:

Running redfin.automation.junit.jupiter.FooTest
A
B
Hello
Tests run: 3, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.059 sec - in redfin.automation.junit.jupiter.FooTest
testFactoryFooA()  Time elapsed: 0.005 sec
testFactoryFooB()  Time elapsed: 0 sec
foo()  Time elapsed: 0.002 sec

Results :

Tests run: 3, Failures: 0, Errors: 0, Skipped: 0

However, if I take out the regular test foo leaving only the TestFactory, and try running mvn clean test again, I get the following output:

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions