我在使用maven项目编译和运行JUnit测试时遇到了问题。
在pom.xml中我添加了这些行来配置surfire插件:
<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>
测试类位于路径“src / test / java //”。
之下当我运行命令mvn test
时,我获得了这个输出:
[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.)
我真的无法弄清楚我错在哪里。
修改 我更改了pom配置如下,因为我也注意到测试类也没有编译:
<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>
通过这种方式,maven开始考虑我的测试源并尝试编译它,即使它无法编译它们,因为我已经使用cxf-codegen-plugin生成代码,测试编译似乎没有看到它。
答案 0 :(得分:2)
错误表示没有测试用例匹配**/Client*.java
。
确保图案正确。另外mvn -X
(启用调试输出)可能会给你一些提示,说明为什么Maven找不到任何测试。
答案 1 :(得分:1)
如果您遵循Maven默认结构(src / main / java中的代码,src / test / java中的测试),则不需要在pom.xml中进行任何特定配置(测试目标是在Maven中构建的)。< / p>
尝试删除特定的surefire配置并运行:
mvn test
答案 2 :(得分:0)