当前位置: 首页 > 面试题库 >

具有Surefire的Maven拒绝运行单一测试方法?

胡野
2023-03-14
问题内容

我一直在尝试将Maven与Surefire插件一起使用以运行一些JUnit单元测试。

遵循Maven和Surefire员工在此处提供的说明:http :
//maven.apache.org/surefire/maven-surefire-plugin/examples/single-
test.html

我对maven的命令如下:

mvn clean -Dtest-group=regression -Dtest=TestClass#testMethod test

TestGroup是从@IfProfileValue语句中提取的,并且一直有效:

@IfProfileValue(name = "test-group", values = {"regression"})

但是,在运行命令后,尽管确定testClass有一个名为testMethod的方法(如果我不将#testMethod添加到命令中,该方法将运行),我的输出如下:

~/REPOS/app: mvn clean -Dtest-group=regression -Dtest=TestClass#testmethod test

[INFO] Scanning for projects...
[WARNING]
[WARNING] Some problems were encountered while building the effective model for com.app:GuiAuto:jar:0.0.1-SNAPSHOT
[WARNING] 'dependencies.dependency.(groupId:artifactId:type:classifier)' must be unique: org.twitter4j:twitter4j-core:jar -> version 2.2.4 vs [3.0,) @ line 127, column 21
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-compiler-plugin is missing. @ line 147, column 12
[WARNING]
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING]
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING]
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building GuiAuto 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ GuiAuto ---
[INFO] Deleting /Users/llaskin/REPOS/app/target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ GuiAuto ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 92 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ GuiAuto ---
[INFO] Compiling 762 source files to /Users/llaskin/REPOS/app/target/classes
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ GuiAuto ---
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 3 resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ GuiAuto ---
[INFO] Compiling 762 source files to /Users/llaskin/REPOS/app/target/test-classes
[INFO]
[INFO] --- maven-surefire-plugin:2.17:test (default-test) @ GuiAuto ---
[INFO] Surefire report directory: /Users/llaskin/REPOS/app/target/surefire-reports
[INFO] parallel='classes', perCoreThreadCount=false, threadCount=5, useUnlimitedThreads=false, threadCountSuites=0, threadCountClasses=0, threadCountMethods=0, parallelOptimized=true

-------------------------------------------------------
 T E S T S
-------------------------------------------------------

Results :

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.379s
[INFO] Finished at: Mon Nov 17 12:27:59 CST 2014
[INFO] Final Memory: 27M/571M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.17:test (default-test) on project GuiAuto: No tests were executed!  (Set -DfailIfNoTests=false to ignore this error.) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[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

问题答案:

可能是因为Surefire
2.16和2.17中的SUREFIRE-1028错误。此错误已在Surefire
2.18中修复。

您能否升级并告诉我们Surefire 2.18是否解决了您的问题。



 类似资料:
  • 我们使用maven surefire插件并行运行测试。由配置文件指定。 我希望在surefire并行运行我的测试之前,每次maven的整个执行过程中只能运行一次方法。我怎么能那么做?

  • 我有一个Java JUnit Selenium测试框架来运行一些测试。有两个类,每个类有两个测试。 我有专家肯定火像这样配置 我希望它同时运行4个测试,但是无论我使用什么组合的、和设置,我似乎一次只能运行1个类的测试用例。看起来这应该行得通,有人能提供解决方案吗?

  • 我有一个maven项目(multimodule,JDK11),其中有很多模块和测试。 编辑:问题发生在一个测试中,该测试属于我公司一个较大项目的一部分,该项目在POM继承链中继承了各种默认值。不幸的是,我不能只把我的POM从它中分离出来并呈现出来。我试图在一个新的独立项目中重现这个问题,但没有成功(也就是说,所有测试都按预期调用了)。 我错过了什么?surefire插件是否有一个隐藏的开关,它揭示

  • 在使用命令时,是否需要maven-surefire插件来运行单元测试? 我阅读了文档,知道它说: Surefire插件在构建生命周期的测试阶段用于执行应用程序的单元测试。它以两种不同的文件格式生成报告: 纯文本文件(. txt)XML文件(. xml)缺省情况下,这些文件是在${Basedir}/Target/surefire-报告中生成的。 然而,我在没有使用surefire插件的情况下运行了这

  • 它是可以配置surefire插件只运行一些测试并行和其他顺序? 也可以使用surefireforkCount来运行声明为jUnit Suite的并行测试吗?

  • 我正在使用SeleniumWebDriver(2.53.0版)的Java实现对web应用程序运行一些自动化测试。测试使用Cucumber的Java实现(版本1.2.3)以行为驱动测试格式编写。我使用Maven(3.3.9版)导入我的所有依赖项,并构建和运行测试。使用cucumber标签将测试分为不同类别。例如,我可以使用以下命令从命令行运行一类标有@JohnnyBravo的测试: 在做了一些研究后