Search code examples
javamavenjunitpluginscucumber-java

I updated my maven-surefire-plugin from 2.20 to 3.1.2 and its giving me an error saying no test cases ran


I am an automation engineer.

WARNING: Unexpected errornet.masterthought.cucumber.ValidationException: No JSON report file was found!at net.masterthought.cucumber.ReportParser.parseJsonFiles(ReportParser.java:61)at net.masterthought.cucumber.ReportBuilder.generateReports(ReportBuilder.java:97)

I'm getting this error when I run [mvn clean test] with maven-surefire-plugin version 3.1.2 but works perfectly when I run with maven-surefire-plugin 2.20. Do I have to configure something in my project for it to work with version 3.1.2? also when I run with version 2.20, the target folder compiles a cucumber.json file but with 3.1.2 it doesn't compile a cucumber.json file. The reason I need to upgrade is because the surefire plugin 2.20 is using a log4j version that a vulnerability.

Below is my pom.xml and my test runner class. I want to know how to run mvn clean test without that error coming back


<pre><code>
  <properties>
        <maven.compiler.source>18</maven.compiler.source>
        <maven.compiler.target>18</maven.compiler.target>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>


<build>

    <plugins>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.11.0</version>
            <configuration>
                <source>18</source>
                <target>18</target>
            </configuration>
        </plugin>

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
                   <version>3.1.2</version>
            <configuration>
                <includes>
                    <include>utility.testRunnerClass</include>
                </includes>
                <testFailureIgnore>true</testFailureIgnore>
            </configuration>
        </plugin>
    <plugin>

        <groupId>net.masterthought</groupId>
        <artifactId>maven-cucumber-reporting</artifactId>
        <version>5.7.5</version>

        <executions>
            <execution>
                <id>execution</id>
                <phase>test</phase>
                <goals>
                    <goal>generate</goal>
                </goals>
                <configuration>
                    <projectName>Automations</projectName> <!-- Replace with project name -->
                    <outputDirectory>target/cucumber/</outputDirectory>
                    <buildNumber>1</buildNumber>
                    <skip>false</skip>
                    <inputDirectory>${project.build.directory}/cucumber</inputDirectory>
                    <jsonFiles> <!-- supports wildcard or name pattern -->
                        <param>**/*.json</param>
                    </jsonFiles> <!-- optional, defaults to outputDirectory if not specified -->
                    <checkBuildResult>false</checkBuildResult>
                </configuration>
            </execution>
        </executions>

    </plugin>

    </plugins>

</build>



</dependencies>
</code></pre>

<pre><code>
package utility;


    @RunWith(Cucumber.class)
    @CucumberOptions(
            features = "src/test/java/features",
            glue = { "stepDefinitions", "utility" },
            tags = "@smoke",
            dryRun = false,
            publish = true,
            plugin = {"pretty", "html:target/cucumber/simple-reports.html",
            "json:target/cucumber/cucumber.json", "junit:target/cucumber/cucumber.xml"}
    )

public class testRunnerClass {

}
</code></pre>

I tried to see what other people did and add junit-jupiter-plugin but gave me back the same error. I just need some help making mvn clean test work with new surefire plugin and have all the correct reports in the target folder like simple reports and cucumber reports


Solution

  • maven-surefire-plugin automatically detect test engine based on your dependencies - but by default only one is used - Junit5 test framework has higer priority and it is used.

    This behavior was changed between 2.x and 3.x version of surefire.

    https://maven.apache.org/surefire/maven-surefire-plugin/examples/junit-platform.html#provider-selection

    If you have mixed JUnit 4 and 5 tests in your projects you need to add junit-vintage-engine to your dependencies

    <dependency>
            <groupId>org.junit.vintage</groupId>
            <artifactId>junit-vintage-engine</artifactId>
            <version><!-- junit 5 version used in project --></version>
            <scope>test</scope>
    </dependency>