java-使用Maven排除特定文件的单元测试

前端之家收集整理的这篇文章主要介绍了java-使用Maven排除特定文件的单元测试 前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我正在研究一个最近获得的项目,并且正在使用mvn test运行单元测试.

因此,我转到不同的模块,并使用cmd运行上述命令,同时我发现2个文件中有两个测试用例,它们都间歇性地失败(该方法上面的注释中已提到).

因此,我正在考虑仅跳过这些测试用例,然后继续进行.我试图在这里找到它,但是我唯一能找到的就是排除特定模块的测试用例.

我想排除A.java的test1()和B.java的test2()

我发现如下:

# Exclude one test method 
mvn verify -Dtest=!LegacyTest#testFoo
# Exclude two test methods
mvn verify -Dtest=!LegacyTest#testFoo+testBar

this链接中,但不确定上述方法的正确性以及在我的情况下如何使用它,因为我以前没有使用过maven

我尝试过的命令:

mvn verify -X -Dtest=!A#test1,!B#test2
mvn test -X -Dtest=!A#test1,!B#test2

运行以上命令后得到的错误跟踪:

[INFO] Selera Utils - Database ............................ SKIPPED
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 18.419 s
[INFO] Finished at: 2019-03-13T19:21:16+05:30
[INFO] Final Memory: 17M/205M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project log4j: No tests were executed!  (Set -DfailIfNoTests=false to ignore this
 error.) -> [Help 1]
org.apache.maven.lifecycle.LifecycleExecutionException: Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.19.1:test (default-test) on project log4j: No tests were exec
uted!  (Set -DfailIfNoTests=false to ignore this error.)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:212)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:153)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:145)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:116)
        at org.apache.maven.lifecycle.internal.LifecycleModuleBuilder.buildProject(LifecycleModuleBuilder.java:80)
        at org.apache.maven.lifecycle.internal.builder.singlethreaded.SingleThreadedBuilder.build(SingleThreadedBuilder.java:51)
        at org.apache.maven.lifecycle.internal.LifecycleStarter.execute(LifecycleStarter.java:120)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:355)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:155)
        at org.apache.maven.cli.MavenCli.execute(MavenCli.java:584)
        at org.apache.maven.cli.MavenCli.doMain(MavenCli.java:216)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:160)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(Launcher.java:289)
        at org.codehaus.plexus.classworlds.launcher.Launcher.launch(Launcher.java:229)
        at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(Launcher.java:415)
        at org.codehaus.plexus.classworlds.launcher.Launcher.main(Launcher.java:356)
Caused by: org.apache.maven.plugin.MojoFailureException: No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.)
        at org.apache.maven.plugin.surefire.AbstractSurefireMojo.execute(AbstractSurefireMojo.java:748)
        at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:132)
        at org.apache.maven.lifecycle.internal.MojoExecutor.execute(MojoExecutor.java:208)
        ... 19 more
[ERROR]
[ERROR]
[ERROR] For more information about the errors and possible solutions,please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
[ERROR]
[ERROR] After correcting the problems,you can resume the build with the command
[ERROR]   mvn <goals> -rf :log4j
最佳答案
链接中,他们说下面的代码运行多个测试:

mvn test -Dtest=AppTest,Web*

所以可能要排除多个:

mvn verify -Dtest=!A#test1,B#test2

我没有尝试,但是似乎合乎逻辑.

– -编辑 – –
您也可以使用插件maven-surefire-plugin,如that

-编辑2-
我尝试并成功,要做的是先验证您是否在版本>中使用了maven-surefire-plugin. 2.19(添加-X以获取调试版本已打印);那么您的命令将是:

mvn test -Dtest=!A#test1,!B#test2
原文链接:https://www.f2er.com/java/532879.html

猜你在找的Java相关文章