简体   繁体   English

Cucumber JUnit 平台引擎。 控制台故障

[英]Cucumber JUnit platform engine. Console failure

I've recently started working with Cucumber JUnit platform engine.我最近开始使用 Cucumber JUnit 平台引擎。 Everything is fine, code is running, however, problem arrises while I am trying to run code via console (mvn clean install -Dtest=CucumberTest).一切都很好,代码正在运行,但是,当我尝试通过控制台运行代码时出现问题(mvn clean install -Dtest=CucumberTest)。

Test run via intelliJ:通过 IntelliJ 测试运行:

在此处输入图像描述

Test run via console:通过控制台测试运行:

From the log perspective in console, I see, that tests were executed, however, in summary I am getting "No tests were executed error".从控制台的日志角度来看,我看到执行了测试,但是,总而言之,我得到“没有执行测试错误”。 What are the reason behind this issue?这个问题背后的原因是什么? Thanks, guys多谢你们

   [INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[ERROR] Apr 28, 2021 2:58:55 PM org.junit.platform.launcher.core.LauncherConfigurationParameters loadClasspathResource
[ERROR] INFO: Loading JUnit Platform configuration parameters from classpath resource [/***/IdeaProjects/cucumber-testing/target/classes/junit-platform.properties].

@ab
Scenario: Scenario21           # steps/suite2.feature:4

@isolated @ab @ac
Scenario: Scenario12           # steps/suite1.feature:9

@isolated @ab @gc
Scenario: Scenario11           # steps/suite1.feature:5

@ab
Scenario: Scenario22           # steps/suite2.feature:8
  When Wait for amount of time # steps.TestSteps.waitFor()
  When Wait for amount of time # steps.TestSteps.waitFor()
  When Wait for amount of time # steps.TestSteps.waitFor()
  When Wait for amount of time # steps.TestSteps.waitFor()
ForkJoinPool-1-worker-5
ForkJoinPool-1-worker-4
ForkJoinPool-1-worker-1
  Then Check thread naming     # steps.TestSteps.getThreadNaming()
  Then Check thread naming     # steps.TestSteps.getThreadNaming()
ForkJoinPool-1-worker-2
  Then Check thread naming     # steps.TestSteps.getThreadNaming()
  Then Check thread naming     # steps.TestSteps.getThreadNaming()
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO] 
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  8.051 s
[INFO] Finished at: 2021-04-28T14:58:57+03:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:3.0.0-M5:test (default-test) on project cucumber: 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

Process finished with exit code 1

My pom.xml file looks like this:我的 pom.xml 文件如下所示:

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>ii.Testing</groupId>
    <artifactId>cucumber</artifactId>
    <version>1.0.0</version>

    <properties>
        <maven-surefire-plugin.version>3.0.0-M5</maven-surefire-plugin.version>
        <cucumber.version>6.10.3</cucumber.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>${cucumber.version}</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit-platform-engine</artifactId>
            <version>${cucumber.version}</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>${cucumber.version}</version>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>${maven-surefire-plugin.version}</version>
            </plugin>
        </plugins>
    </build>
</project>

It seems IntelliJ is using the Junit4 way of using Cucumber contrary to Maven which is using the Junit5 way.似乎 IntelliJ 使用 Junit4 方式使用 Cucumber 与使用 Junit5 方式的 Maven 相反。 If you want to use the Junit4 way you need to remove cucumber-junit-platform-engine from your dependencies.如果要使用 Junit4 方式,则需要从依赖项中删除cucumber-junit-platform-engine

To use Cucumber with Junit5, it's not out of the box and it's not well documented.要将 Cucumber 与 Junit5 一起使用,它不是开箱即用的,也没有很好的文档记录。

First you need to remove the dependency cucumber-junit :首先,您需要删除依赖cucumber-junit

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>${cucumber.version}</version>
    </dependency>

Because it's related to the Junit4 way of using Cucumber .因为它与使用 Cucumber 的 Junit4 方式有关

You already have the dependency for Cucumber with Junit5 :您已经拥有 Cucumber 与Junit5的依赖关系:

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit-platform-engine</artifactId>
        <version>${cucumber.version}</version>
    </dependency>

In your code you need to replace the use of:在您的代码中,您需要替换以下内容的使用:

@RunWith(Cucumber.class)
@CucumberOptions(...)

By io.cucumber.junit.platform.engine.Cucumber from cucumber-junit-platform-engine:作者: io.cucumber.junit.platform.engine.Z039892FD59A649C7EEEAE20450AFB4

@Cucumber

The last trick to make it Junit5 compliant is to move the feature files under the same repository structure as the package annoyed by @Cucumber meaning ii.Testing.cucumber.CucumberIT annoted by @Cucumber needs to have the feature files under the following folder structure:使其与 Junit5 兼容的最后一个技巧是将功能文件移动到与 @Cucumber 所困扰的package相同的存储库结构下

  • ii\testing\cucumber ii\测试\黄瓜

With all *.feature in it or in subfolder under it.包含所有 *.feature 在其中或其下的子文件夹中。

The last thing is to have cucumber properties working and the only way I managed to make it work with Junit5 is by using junit-platform.properties and add directly the property.最后一件事是让 cucumber 属性工作,我设法使其与 Junit5 一起工作的唯一方法是使用junit-platform.properties并直接添加属性。

By example:举例:

cucumber.publish.quiet=true
cucumber.plugin=pretty, summary, html:target/cucumber/report.html,json:target/cucumber/cucumber.json,junit:target/cucumber/cucumber.xml
cucumber.filter.tags=not @not-implemented and not @manual and not @unit-test

暂无
暂无

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

相关问题 @CucumberOptions 在cucumber-junit-platform-engine 中 - @CucumberOptions in cucumber-junit-platform-engine Cucumber-junit-platform-engine 中的特征文件发现 - Feature files discovery in cucumber-junit-platform-engine java - JUnit测试失败钩子上的黄瓜 - java - Cucumber on JUnit Test Failure Hook cucumber-junit-platform 中缺少步骤通知 - Lack of step-notifications in cucumber-junit-platform 使用 Cucumber JUnit5 引擎选择单个测试失败 - Selecting a single test with Cucumber JUnit5 engine fails Struts 2在谷歌应用引擎上。 问题 - Struts 2 on Google app engine. problem 我不断收到 java.lang.NoClassDefFoundError: org/junit/platform/engine/ConfigurationParameters 和 Eclipse,但安装了 Junit5 - I keep getting a java.lang.NoClassDefFoundError: org/junit/platform/engine/ConfigurationParameters with Eclipse, but Junit5 installed java.lang.ClassNotFoundException: org.junit.platform.engine.ConfigurationParameters Junit5 与 eclipse - java.lang.ClassNotFoundException: org.junit.platform.engine.ConfigurationParameters Junit5 with eclipse 使用 JUnit5 时,我收到警告:“ClassNotFoundException: org.junit.platform.engine.support.filter.ExclusionReasonConsumingFilter” - When using JUnit5, I got a warning: "ClassNotFoundException: org.junit.platform.engine.support.filter.ExclusionReasonConsumingFilter" Cucumber 使用基于 JUnit5 平台的外部运行器运行测试时出现 UndefinedStepException - Cucumber UndefinedStepException when running tests with external runner based on JUnit5 platform
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM