简体   繁体   English

没有“测试运行:0,失败:0,错误:0,跳过:0”,即使 cucumber 测试是使用“mvn test”命令执行的

[英]no "Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, " even that cucumber test was executed using "mvn test" command

Could someone suggest me a solution why when I run the test using command mvn test to run the cucumber runner class ExampleRunnerTest located in \src\test\java it runs but the maven build doesn't recognize it.有人可以建议我一个解决方案,为什么当我使用命令mvn test运行测试来运行 cucumber 运行器 class ExampleRunnerTest位于\src\test\java它运行但 Z402C5D9AF6B43711EA070BEE5170F7 没有识别它。 Like I said the test runs does what it should do but the build still fails.就像我说的测试运行做了它应该做的,但构建仍然失败。

1 Scenarios (←[32m1 passed←[0m)
6 Steps (←[32m6 passed←[0m)
1m36.764s

Tests run: 0, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 98.777 sec - in BasicTest

Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------

@RunWith(Cucumber.class)
@CucumberOptions(features = "src/main/java/cucumber/feature/Basic.feature", glue = "cucumber/stepDefinition",
    format = {"pretty", "html:target/cucumber", "json:target/cucumber-report.json"})

public class BasicTest {
}

When I had this problem in my Selenium project I realized that I was using junit and TestNG as well.当我在 Selenium 项目中遇到这个问题时,我意识到我也在使用 junit 和 TestNG。 I removed TestNG codes and dependency from pom.xml.我从 pom.xml 中删除了 TestNG 代码和依赖项。 This way I only had junit in my project left.这样我的项目中只剩下junit了。 Then everything worked like charm, MVN test results showed the correct numbers.然后一切正常,MVN 测试结果显示正确的数字。

Replica-复制品-

Rai Gupta is right.
The dependency was an issue for me also. 
I saw too many "Append your runner class with Test, move the runner class into TEST folder" etc. 

But you are just destroying the whole design and it will end with differently designed framework.但是你只是在破坏整个设计,它会以不同设计的框架结束。

JUnit and SureFire plugin need to be aligned. I used 
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.13.1</version>
    <scope>test</scope>
</dependency>

AND

<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>

However, this came in with a parallel execution problem. I did not need it, removed. But you can try different versions of the above dependency.

Lastly, this worked or me: Tests not running through Maven?最后,这对我有用测试没有通过 Maven 运行?

    <dependency>
        <groupId>org.junit.jupiter</groupId>
        <artifactId>junit-jupiter-engine</artifactId>
        <version>5.3.2</version>
    </dependency>

This is what I did for it to work for me这就是我所做的让它为我工作

  1. Like user = BlondCode said remover or comment TestNG dependency from you pom.xml file.就像 user = BlondCode 说从你的 pom.xml 文件中删除或评论 TestNG 依赖项一样。

  2. Add JUnit vintage engine dependency to pom.xml将 JUnit 老式引擎依赖项添加到 pom.xml

  3. Add a resources folder where you will store your feature and step definitions packages eg = \\src\\test\\java\\resources\\feature and \\src\\test\\java\\resources\\step definitions添加一个资源文件夹,您将在其中存储您的功能和步骤定义包,例如 = \\src\\test\\java\\resources\\feature 和 \\src\\test\\java\\resources\\step definition

  4. You runner package remains in \\src\\test\\java folder您的 runner 包保留在 \\src\\test\\java 文件夹中

  5. Last but not the least add the below configuration to surefire plugging.最后但并非最不重要的是,将以下配置添加到万无一失的插入中。 See image below见下图

在此处输入图片说明

This could be issue with jUnit supprt in surefire lib.这可能是 surefire 库中 jUnit 支持的问题。 I followed this link to fix the issue.我按照这个链接来解决这个问题。
It works !有用 ! Why Your JUnit 5 Tests Are Not Running Under Maven 为什么您的 JUnit 5 测试未在 Maven 下运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM