Reputation: 41
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?
Upvotes: 4
Views: 1547
Reputation: 872
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)
Upvotes: 2
Reputation: 2050
Have you tried changing the workingDirectory:
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<workingDirectory>wherever you have your tests</workingDirectory>
<useFile>false</useFile>
<includes>
<include>**/*Spec.groovy</include>
<include>**/*Test.groovy</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
UPDATED 11/01/2018: Not sure that would solve the issue, but can you try to add those dependencies as reporting ones (outside the build dependencies):
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<showSuccess>true</showSuccess>
<linkXRef>false</linkXRef>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>
</plugins>
</reporting>
Upvotes: 0