无法使用 Maven 运行单个测试方法
我知道如何运行 Junit 测试类:
mvn test -Dtest=classname
,但是当我尝试运行单个单元测试方法时,如下所示:
mvn test -Dtest=classname#methodname
我总是收到错误:没有测试执行
参考:
http://maven.apache.org/plugins/maven-surefire-plugin/examples/single-test.html http://stackoverflow.com/questions/1873995/run-a-single-test-method-with-maven
请告知为什么我的测试方法没有被执行,我正在使用 maven 2 和 < junit 4.7 。
i know how to run Junit test class:
mvn test -Dtest=classname
but when i tried to run a single unit test method as follows:
mvn test -Dtest=classname#methodname
i always get the error: that no test were executed
References:
http://maven.apache.org/plugins/maven-surefire-plugin/examples/single-test.html
http://stackoverflow.com/questions/1873995/run-a-single-test-method-with-maven
please advise why my test method is not getting execusted, i am using maven 2 and junit 4.7 .
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
上面的语法仅支持 Maven Surefire 版本 2.7.3+
确保您使用的是正确版本的插件。
The syntax above is only supported for Maven Surefire version 2.7.3+
Make sure you're using the correct version of the plugin.
Surefire 2.12 有一个问题。
这就是我将 maven-surefire-plugin 从 2.12 更改为 2.11 时发生的情况:
mvn test -Dtest=DesignRulesTest
结果:
[错误] 无法在项目 pmd 上执行目标 org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test): 未执行任何测试!强>
mvn 测试 -Dtest=DesignRulesTest
结果:
[信息] --- maven-surefire-plugin:2.11:test (默认测试) @ pmd ---
...
运行 net.sourceforge.pmd.lang.java.rule.design.DesignRulesTest
测试运行:5,失败:0,错误:0,跳过:4,已用时间:4.009 秒
There is an issue with surefire 2.12.
This is what happen to me changing maven-surefire-plugin from 2.12 to 2.11:
mvn test -Dtest=DesignRulesTest
Result:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project pmd: No tests were executed!
mvn test -Dtest=DesignRulesTest
Result:
[INFO] --- maven-surefire-plugin:2.11:test (default-test) @ pmd ---
...
Running net.sourceforge.pmd.lang.java.rule.design.DesignRulesTest
Tests run: 5, Failures: 0, Errors: 0, Skipped: 4, Time elapsed: 4.009 sec
从 Maven 项目目录执行:
注意使用
surefire
参考:https://maven.apache.org/surefire/maven- Surefire-plugin/examples/single-test.html
From Maven project dir execute :
note use of
surefire
Reference : https://maven.apache.org/surefire/maven-surefire-plugin/examples/single-test.html