0

I'm having trouble compiling and running JUnit tests using a maven project.

In the pom.xml I added those lines to configure the surfire plugin:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.16</version>
    <configuration>
        <encoding>UTF-8</encoding>                    
        <skipTests>false</skipTests>                                 
        <includes>
            <include>**/*.java</include>
        </includes>
    </configuration>

    <executions>
        <execution>
            <id>unit-test</id>
            <phase>test</phase>
            <goals>
                <goal>test</goal>
            </goals>
            <configuration>
                <skip>false</skip>
                <includes>
                    <include>**/Client*.java</include>
                </includes>   
            </configuration>
        </execution>
    </executions>
</plugin>

the tests classes are under the path "src/test/java//".

When I run the command mvn test I obtain this output:

[INFO] Storing buildScmBranch: trunk
[INFO] [resources:resources {execution: default-resources}]
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] Copying 10 resources
[INFO] [cxf-codegen:wsdl2java {execution: generate-sources}]
[INFO] [compiler:compile {execution: default-compile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [resources:testResources {execution: default-testResources}]
[INFO] Not copying test resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Not compiling test sources
[INFO] [surefire:test {execution: default-test}]
[INFO] Tests are skipped.
[INFO] [surefire:test {execution: unit-test}]
[INFO] No tests to run.
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.)

I really can't figure out where I'm wrong.

EDIT: I changed the pom configuration as follows, because I also noticed that the tests classes were also not compiled:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.0.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.6</target>
    </configuration>
    <executions>
        <execution>
            <id>default-testCompile</id>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
                <skip>false</skip>
                <additionalClasspathElements>
                    <additionalClasspathElement>${basedir}/target/*.jar</additionalClasspathElement>
                </additionalClasspathElements>
                <directory>${basedir}/src/test/java</directory>
                <includes>
                    <include>**/*.*</include>
                </includes> 
            </configuration>
        </execution>
    </executions>
</plugin>

In this way maven start to consider my test sources and try to compile it, even if it fails to compile them because I have generated code with cxf-codegen-plugin, that test compilation seems not to see it.

ROMANIA_engineer
  • 54,432
  • 29
  • 203
  • 199
Stefania
  • 641
  • 1
  • 12
  • 34

3 Answers3

2

The error means that no test case matches **/Client*.java.

Make sure the pattern is correct. Also mvn -X (enable debug output) might give you some hints as to why Maven can't locate any tests.

Aaron Digulla
  • 321,842
  • 108
  • 597
  • 820
  • All the test classes are under their package directory. Have I to specify it or "**" is enough? running mvn -X didn't give me more hints. – Stefania Aug 21 '13 at 12:24
  • Names of test classes should end with "Test". The default pattern is `**/*Test.java`. If you want all files, the pattern should be `**/*.java` – Aaron Digulla Aug 21 '13 at 13:33
  • Thank you very much, I substituted my **/Client*.java with **/*.java – Stefania Aug 21 '13 at 14:30
1

If you are following Maven default structure (code in src/main/java, tests in src/test/java), you do not need any specific configuration in your pom.xml (test goals are built in Maven).

Try removing the specific surefire config and just running:

mvn test
Martin
  • 7,634
  • 1
  • 20
  • 23
  • I added the surefire configuration because test still didn't work, hoping to solve the problem. – Stefania Aug 21 '13 at 12:25
  • 1
    "Tests didn't work": was the error message the same (no test to run)? Can you post your project' structure? mvn test should be enough. – Martin Aug 21 '13 at 13:13
  • the error message was "tests are skipped", for this reason I decided to configure surfire in the pom.xml. The project structure is the standard one. – Stefania Aug 21 '13 at 14:28
0

Maybe a maven surefire plugin defect as described here or here.

Community
  • 1
  • 1
Felix
  • 3,999
  • 3
  • 42
  • 66