[英]maven run junit test
I'm having trouble compiling and running JUnit tests using a maven project. 我在使用Maven项目编译和运行JUnit测试时遇到问题。
In the pom.xml I added those lines to configure the surfire plugin: 在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>
the tests classes are under the path "src/test/java//". 测试类位于路径“ src / test / java //”下。
When I run the command mvn test
I obtain this output: 当我运行命令
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.)
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: 编辑:我更改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>
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. 这样,即使我因为使用cxf-codegen-plugin生成了代码而无法编译它们,maven仍开始考虑我的测试源并尝试对其进行编译,但该测试编译似乎看不到它。
The error means that no test case matches **/Client*.java
. 该错误意味着没有测试用例匹配
**/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. 同样,
mvn -X
(启用调试输出)可能会提示您Maven为什么找不到任何测试。
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). 如果您遵循Maven的默认结构(src / main / java中的代码,src / test / java中的测试),则pom.xml中不需要任何特定配置(测试目标内置于Maven中)。
Try removing the specific surefire config and just running: 尝试删除特定的surefire配置并开始运行:
mvn test
Maybe a maven surefire plugin defect as described here or here . 可能是此处或此处所述的Maven surefire插件缺陷。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.