【问题标题】:Cucumber: NoSuchMethodError: cucumber.runtime.formatter.Plugins黄瓜:NoSuchMethodError:黄瓜.runtime.formatter.Plugins
【发布时间】:2019-06-16 12:55:12
【问题描述】:

我在 IntelliJ 的主题中遇到异常,但不知道为什么。

这是跑步者文件:

@RunWith(Cucumber.class)
@CucumberOptions(
        features = "src/main/resources/features",
        glue = {"DemoDefinitions"},
        tags = "@tests"
        )
public class CucumberRunner {}

这是定义文件:

import cucumber.api.java.en.Given;

public class DemoDefinitions {

    @Given("Login to Azure Succeeded")
    public void login_to_Azure_Succeeded() {
        // Write code here that turns the phrase above into concrete actions
        throw new cucumber.api.PendingException();
    }
}

这是功能文件:

@tests

Feature: PoC Feature

  Scenario: PoC Operations Scenario
    Given Login to Azure Succeeded

而maven依赖是:

<dependencies>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>4.4.0</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-java</artifactId>
        <version>4.2.6</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-junit</artifactId>
        <version>4.2.6</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
    </dependency>
</dependencies>

当我运行时执行我得到的 runner 类:

java.lang.NoSuchMethodError: cucumber.runtime.formatter.Plugins.(Ljava/lang/ClassLoader;Lcucumber/runtime/formatter/PluginFactory;Lcucumber/api/event/EventPublisher;Lio/cucumber/core/options/PluginOptions;)V

当我运行功能文件本身时,我得到:

未定义的场景: /C:/Users/talt/IdeaProjects/Poc/src/main/resources/features/poc.feature:5 PoC运营场景

1 个场景(1 个未定义)1 个步骤(1 个未定义)

你能告诉我是什么问题吗?

【问题讨论】:

    标签: cucumber cucumber-jvm cucumber-java cucumber-junit


    【解决方案1】:

    您正在混合不同版本的 Cucumber。请仔细查看版本号。

    您还包括更多的依赖项,然后是严格需要的。仅使用cucumber-javacucumber-junit 就足够了。 cucumber-corejunit 都是传递依赖。

    修复依赖项后,请确保重新导入 maven 项目。

    <dependencies>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-java</artifactId>
            <version>4.4.0</version>
        </dependency>
        <dependency>
            <groupId>io.cucumber</groupId>
            <artifactId>cucumber-junit</artifactId>
            <version>4.4.0</version>
        </dependency>
    </dependencies>
    

    【讨论】:

    • 谢谢mpkorstanje。它没有做出改变。但是我发现了错误并修复了它。看我的回答。
    • 你仍然应该清理你的导入。
    【解决方案2】:

    解决方案是将胶水设置为空字符串:

    glue = {""}
    

    【讨论】:

      【解决方案3】:

      我们不会混合直接依赖和传递依赖,尤其是它们的版本!这样做会导致不可预测的结果。以下是由于错误使用依赖而被人们报告的一些错误。

      • 导入 cucumber.api.junit 无法解析
      • java.lang.NoClassDefFoundError: gherkin/IGherkinDialectProvider
      • 导入黄瓜.api.DataTable;无法解决

      解决方案:你应该添加正确的黄瓜依赖集。

          <dependency>
          <groupId>io.cucumber</groupId>
          <artifactId>cucumber-junit</artifactId>
          <version>4.2.6</version>
          <scope>test</scope>
          </dependency>
      
          <dependency>
          <groupId>io.cucumber</groupId>
          <artifactId>cucumber-picocontainer</artifactId>
          <version>4.2.6</version>
          <scope>test</scope>
          </dependency>
      

      第二你可以说我们没有指向胶水的正确路径。但是,即使它有效,仅仅将其清空也不应该是解决方案之一。我们在这里应该有正确的路径,而不是空字符串。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2019-12-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-07-18
        相关资源
        最近更新 更多