使用io.Cucumber找不到步骤定义(java8 - testng - spring)

时间:2018-05-28 14:21:51

标签: java cucumber cucumber-jvm cucumber-java testng-dataprovider

我升级了黄瓜版本,用于在不同的@Test中运行每个黄瓜场景,但现在我的跑步者无法找到我的步骤定义 当我使用带有groupId Info.cukes的黄瓜1.2.5时,我的测试运行正常但是我知道我已经迁移到3.0.1我的所有测试都被跳过,我的场景未定义。 我的跑步者:

@CucumberOptions(
    plugin = {"pretty", "html:target/cucumber"},
    features = "src/main/java/cucumbertests/features"
    , glue = {"cucumbertests.stepdef.customer.CreateCustomerSteps",
    "cucumbertests.stepdef.customer.CustomerTestSteps"
}
)
public class CucumberTestRunner {
    private TestNGCucumberRunner testNGCucumberRunner;

    @BeforeClass(alwaysRun = true)
    public void setUpClass() throws Exception {
        testNGCucumberRunner = new TestNGCucumberRunner(this.getClass());
}

    @Test(description = "Runs Cucumber Scenarios", dataProvider = "scenarios")
    public void scenario(PickleEventWrapper pickleEvent, CucumberFeatureWrapper cucumberFeature) throws Throwable {
        testNGCucumberRunner.runScenario(pickleEvent.getPickleEvent());
    }

    @DataProvider
    public Object[][] scenarios() {
        return testNGCucumberRunner.provideScenarios();
    }

    @AfterClass(alwaysRun = true)
    public void tearDownClass() throws Exception {
        testNGCucumberRunner.finish();
    }
}

我正在使用黄瓜3.0.1的版本

<cucumber.version>3.0.1</cucumber.version>

    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-jvm</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-core</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-testng</artifactId>
        <version>${cucumber.version}</version>
    </dependency>
    <dependency>
        <groupId>io.cucumber</groupId>
        <artifactId>cucumber-spring</artifactId>
        <version>${cucumber.version}</version>
    </dependency>

1 个答案:

答案 0 :(得分:0)

如果你看看cucumber-jvm repo中的testng发行说明 - https://github.com/cucumber/cucumber-jvm/tree/master/testng。有一个示例链接可以运行TestNGCucumberRunner - https://github.com/cucumber/cucumber-jvm/blob/master/examples/java-calculator-testng/src/test/java/cucumber/examples/java/calculator/RunCukesByCompositionTest.java

它在测试(scenario())方法中具有其他组参数 - groups = "cucumber"。也许这解决了问题