【问题标题】:cucumber.runtime.CucumberException: No backends were foundcucumber.runtime.CucumberException:没有找到后端
【发布时间】:2020-07-17 17:24:30
【问题描述】:

我正在尝试在 Maven 项目中使用黄瓜运行 BDD 测试。 当我尝试运行 BDDdemo.feature 时,出现以下错误

Exception in thread "main" cucumber.runtime.CucumberException: No backends were found. Please make sure you have a backend module on your CLASSPATH.
    at cucumber.runtime.Runtime.<init>(Runtime.java:81)
    at cucumber.runtime.Runtime.<init>(Runtime.java:70)
    at cucumber.runtime.Runtime.<init>(Runtime.java:66)
    at cucumber.api.cli.Main.run(Main.java:35)
    at cucumber.api.cli.Main.main(Main.java:18)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:567)
    at com.intellij.rt.execution.application.AppMainV2.main(AppMainV2.java:131)

环境

openjdk 版本:13.0.1
Apache Maven:3.6.3
测试NG:6.14.3
黄瓜:1.2.6
IDE:IntelJ IDEA

依赖

        <dependency>
            <groupId>org.testng</groupId>
            <artifactId>testng</artifactId>
            <version>6.14.3</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.13</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.seleniumhq.selenium</groupId>
            <artifactId>selenium-java</artifactId>
            <version>3.141.59</version>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.6</version>
            <!--<type>pom</type>-->
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-testng</artifactId>
            <version>1.2.6</version>
            <!--<type>pom</type>-->
        </dependency>
        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>1.2.6</version>
            <!--<type>pom</type>-->
        </dependency>
        <dependency>
            <groupId>net.masterthought</groupId>
            <artifactId>cucumber-reporting</artifactId>
            <version>5.3.0</version>
        </dependency>

我已经尝试了有关此问题的堆栈溢出的所有解决方案。但没有什么对我有用。
谁能帮我解决这个问题?

【问题讨论】:

    标签: java maven cucumber testng cucumber-jvm


    【解决方案1】:

    我假设,根据您的pom.xml sn-p,您正在使用 TestNGJunit。因此,您需要同时添加 cucumber-testng(它已经存在)和 cucumber-junit(它已丢失)作为 cucumber 后端。请考虑将此其他依赖项添加到您的 pom.xml 的依赖项部分:

        <dependency>
            <groupId>info.cukes</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>1.2.6</version>
        </dependency>
    

    PS:您列出的所有依赖项似乎都是测试范围的,因此,请考虑将 &lt;scope&gt;tests&lt;/scope&gt; 添加到每个依赖项中,以避免不必要地将这些库添加到最终包中(如果您正在打包 JAR )。

    【讨论】:

    • 感谢您的回答。但我已经添加了cucumber-junit。你可以在我的 pom.xml 中看到。
    • 成功了!我在每个依赖项中添加了&lt;scope&gt;tests&lt;/scope&gt;。不知何故,它终于奏效了。虽然我不知道为什么它真的有效。
    猜你喜欢
    • 2020-07-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-11-02
    • 2021-11-05
    • 1970-01-01
    • 2023-02-24
    • 2018-06-30
    相关资源
    最近更新 更多