0
votes

I'm using JUnit 5.3.1 and running tests using maven. There is a parametrised test which is not running. I am using maven-surefire-plugin and this is from my pom.xml

<build>
        <plugins>
            <plugin>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.19</version>
                <configuration>
                    <includes>
                        <include>**/*Tests.java,**/*Test.java</include>
                    </includes>
                </configuration>
            </plugin>
...
</build>

When I run mvn test command, this is a part of the output:

Running com.growthintel.elastic_plugin.cid_suppressions.CheckCompanyTest Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0 sec - in com.growthintel.elastic_plugin.cid_suppressions.CheckCompanyTest

There are no tests being detected from CheckCompanyTest file! Maven is detecting the file but not detecting any tests within the file. Is there a naming convention for parametrised tests that I am not following? Here is the test file:

public class CheckCompanyTest {

        private static Stream<Arguments> getListOfSuppressedFilePaths() {
            ...
        }

        @ParameterizedTest(name = "run #{index} with args: {arguments}")
        @MethodSource("getListOfSuppressedFilePaths")
        public void test_HasSuppressedCid(List<String> cidSuppressionFilePaths) {
            ...
}
2
Upgrade Surefire to 2.22.0 and use JUnit Jupiter 5.2.0 for now. - Sormuras
@Sormuras I tried a combination of JUnit 5.2.0 and maven-surefire-plugin v2.22.0 and it did not work. Thanks for the suggestion though!. - Chirayu Shishodiya
Remove the include cause it's default in maven-surefire-plugin... - khmarbaise

2 Answers

2
votes

You could use the junit-platform-surefire-engine, like @Niby suggested, or upgrade your maven-surefire-plugin to 2.22.0, and use the built-in support for JUnit Jupiter:

<plugin>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.22.0</version> <!-- Here -->
    <configuration>
        <includes>
            <include>**/*Tests.java,**/*Test.java</include>
        </includes>
    </configuration>
</plugin>
-1
votes

JUnit 5 is not supported by the maven.surefire plugin version 2.19, so you have to add a custom provider and engine to the plugin, if you need to use that version.

Like this:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <dependencies>
        <dependency>
            <groupId>org.junit.platform</groupId>
            <artifactId>junit-platform-surefire-provider</artifactId>
            <version>1.3.1</version>
        </dependency>
        <dependency>
            <groupId>org.junit.jupiter</groupId>
            <artifactId>junit-jupiter-engine</artifactId>
            <version>5.3.1</version>
        </dependency>
    </dependencies>
    <configuration>
        <includes>
             <include>**/*Tests.java,**/*Test.java</include>
        </includes>
    </configuration>
</plugin>

Your exact version of JUnit 5 may of course be different, so pay attention to the version numbers.