Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Maven Surefire not executing test phase

When running mvn test it appears that surefire is not executing it's test goal (or at the very least is not picking up the tests which I have included within the configuration.

This is a multi-module maven project, currently all in groovy, with a structure similar to the below:

root
-commons
-framework
-generatedsources1
-generatedsources2
-test-groups
--test-group1
---src/test/java/path.to.TestClass.groovy
--test-group2

I have the follow surefire configuration within the test-groups pom.xml:

<build>
    <plugins>
        <plugin>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.18.1</version>
            <configuration>
                <useFile>false</useFile>
                <includes>
                    <include>**/*Spec.groovy</include>
                    <include>**/*Test.groovy</include>
                </includes>
            </configuration>
        </plugin>
    </plugins>
</build>

However when I execute mvn test against this pom.xml, or either of the sub-poms, the test phase is never executed.

This is the maven output:

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building system-test-category-man 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- gmavenplus-plugin:1.6:compile (default) @ system-test-category-man ---
[INFO] Using Groovy 2.4.9 to perform compile.
[INFO] Compiled 2 files.
[INFO] 
[INFO] --- gmavenplus-plugin:1.6:compileTests (default) @ system-test-category-man ---
[INFO] Using Groovy 2.4.9 to perform compileTests.
[INFO] Compiled 3 files.
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.809 s
[INFO] Finished at: 2018-01-08T10:53:29Z
[INFO] Final Memory: 20M/175M
[INFO] ------------------------------------------------------------------------

And when I call the plugin directly:

[INFO] Scanning for projects...
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] Building system-test-category-man 1.0.0
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-surefire-plugin:2.18.1:test (default-cli) @ system-test-category-man ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.315 s
[INFO] Finished at: 2018-01-08T10:58:18Z
[INFO] Final Memory: 9M/155M
[INFO] ------------------------------------------------------------------------

Have I misconfigured anything?

like image 947
EJ-K Avatar asked Sep 14 '25 08:09

EJ-K


1 Answers

The question puzzled me too, but I think I found out what the problem is.

From the perspective of the maven-surefire-plugin Groovy classes are nothing but meaningless text files, it cannot scan it for annotations. But instead of specifying Groovy sources, I could successfully specify <includes> in terms of class names (this example should pick up everything):

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.12.4</version>
                <configuration>
                    <includes>
                        <include>**/*.class</include>
                    </includes>
                </configuration>
            </plugin>

Otherwise you must name your tests (your Groovy test classes) according to the default naming convention that is documented here: http://maven.apache.org/surefire/maven-surefire-plugin/test-mojo.html#includes and goes like this:

<includes>
    <include>**/Test*.java</include>
    <include>**/*Test.java</include>
    <include>**/*Tests.java</include>
    <include>**/*TestCase.java</include>
</includes>

(mentally replace .java with .groovy here)

like image 171
nineninesevenfour Avatar answered Sep 15 '25 21:09

nineninesevenfour