我在使用Maven项目编译和运行JUnit测试时遇到了问题。maven run junit test
在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 /测试/ 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>
这样行家开始考虑我的测试源,并尝试编译它,即使它没有编译它们,因为我已经用cxf-codegen-plugin生成了代码,但是测试编译似乎没有看到它。
我加入了万无一失的配置,因为测试仍然没有工作,希望能解决这个问题。 –
“测试无法正常工作”:错误信息相同(没有测试运行)?你能发布你的项目结构吗? mvn测试应该足够了。 – Martin
错误消息是“测试被跳过”,因此我决定在pom.xml中配置surfire。项目结构是标准的。 –