在 Cucumber 胶水选项包中使用多个 类

Using multiple classes in Cucumber glue option package

我在 运行ning Cucumber 测试时使用胶水选项时遇到问题。这是我的测试 运行ner class:

@RunWith(Cucumber.class)
@CucumberOptions(features="src/test/java/com/xcase/tests/cucumber/features/api/APITest.feature",glue={"com.xcase.tests.cucumber.stepdefinitions.api"})
public class APIRunnerTest {

}

我运行 沿着这些方向进行测试:

mvn clean test -Dtest=APIRunnerTest

如果我将所有步骤定义放在胶水包 class 中,com.xcase.tests.cucumber.stepdefinitions.api.FirstSteps,那么我的测试 运行 没问题。

如果我向 com.xcase.tests.cucumber.stepdefinitions.api 包添加一个空的 class,比如 com.xcase.tests.cucumber.stepdefinitions.api.SecondSteps,那么我的测试 运行 没问题。但是,如果我修改 SecondSteps 以扩展 FirstSteps,那么我的测试将完全停止 运行ning!这是为什么?

这对我来说是个问题,因为我想将一些共享步骤定义和字段放在基本步骤定义中 class,然后有多个 class 扩展基本步骤 class。我应该怎么做?

However, if I modify SecondSteps to extend FirstSteps, then my tests stop running completely! Why is that?

您现在有两个 类 声明步骤。因为 SecondSteps 扩展了 FirstStepsSecondSteps 将声明与 FirstSteps 完全相同的步骤。所以 Cucumber 无法决定哪些步骤应该 运行。

This is a problem for me because I'd like to put some shared step definitions and fields in a base step definition class and then have multiple classes that extend the base class. How should I do this?

如果您想在步骤之间共享信息,您应该使用 a world object. The documentation uses ruby but after adding cucumber-pico as a dependency it works the same way in Java. For a dated tutorial check Sharing state between steps in Cucumber-JVM using PicoContainer