Question

After upgrading all my Maven plugins version for a project, I encountered the following problem: when I run the basic command mvn test -Dtest=SomeTest, the build finishes with no test executed at all. In fact, I am not able to run any test using -Dtest parameter (of course the test exist, and is run when I simply execute mvn test).

After some searches, it appears that the problem is due to the usage of surefire 2.12 plugin. I've tested several versions of Maven (2.2.1 / 3.0.2) and JUnit (4.7.x, 4.8, 4.10, or even 3.8.x), but they have no impact on my issue.

So maybe my project has some specific configurations that may have an impact on that? Anyway, I created a new project, using mvn archetype:generate (using the basic org.apache.maven.archetypes:maven-archetype-quickstart).

I modified only 2 things in the pom.xml: using JUnit 4.10 (but it didn't change anything, I've tried with others versions), and defining the version of surefire:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>foo</groupId>
    <artifactId>bar</artifactId>
    <version>1.0-SNAPSHOT</version>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.10</version>
            <scope>test</scope>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.11</version>
            </plugin>
        </plugins>
    </build>
</project>

I run mvn test -Dtest=AppTest (the default JUnit test created by the archetype):

-------------------------------------------------------  T E S T S
------------------------------------------------------- Running foo.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time
elapsed: 0.031 sec

Results :

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

[INFO]
------------------------------------------------------------------------ [INFO] BUILD SUCCESS [INFO]

Now, I modify the pom.xml to use version 2.12 for Surefire and run the command again:

-------------------------------------------------------  T E S T S

Results :

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

[INFO]
------------------------------------------------------------------------ [INFO] BUILD FAILURE [INFO]
------------------------------------------------------------------------ [INFO] Total time: 0.907s [INFO] Finished at: Fri Mar 02 10:37:12 CET
2012 [INFO] Final Memory: 3M/15M [INFO]
------------------------------------------------------------------------ [ERROR] Failed to execute goal
org.apache.maven.plugins:maven-surefire-plugin:2.12:test
(default-test) on project bar: No tests were executed!  (Set -D
failIfNoTests=false to ignore this error.) -> [Help 1]

The test is not run this time :(

As far as I am concerned, I think it's a regression, but that's quite surprising. Indeed, a JIRA defect is logged on Surefire 2.12 version, and in this description, they succeed in using -Dtest parameter.

Am I doing something wrong? Or is it a real regression (in this case, I will create the JIRA)?

Thanks.

Was it helpful?

Solution

It's a bug in 2.12 version - SUREFIRE-827.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top