黄瓜:NoSuchMethodError:黄瓜。运行时。格式器。插件

时间:2019-06-16 12:55:12

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

我在IntelliJ上遇到了一个例外,不知道为什么。

Project structure

这是跑步者文件:

@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>

运行跑步类时,我得到:

  

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

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

  

未定义的方案:   / C:/用户/talt/IdeaProjects/Poc/src/main/resources/features/poc.feature:5   PoC运营方案

     

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

请问是什么问题?

3 个答案:

答案 0 :(得分:2)

您要混合使用不同版本的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>

答案 1 :(得分:1)

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

glue = {""}

答案 2 :(得分:1)

我们将不混合直接和传递依赖关系,特别是它们的版本!这样做可能会导致不可预测的结果。以下是由于错误使用依赖关系而导致人们报告的错误。

  • 无法解析导入的cumul.api.junit
  • java.lang.NoClassDefFoundError:gherkin / IGherkinDialectProvider
  • 导入cumul.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>

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