Cucumber - implementing missing steps in java

2019-08-14 16:59发布

I have the below cucumber feature without any corresponding java code actions.

@CucumberTest
Scenario: Testing cucumber
 Given I have this test.
 When I test This
 Then I get this

When I run it I get the following results

    1 Scenarios (1 undefined)
    3 Steps (3 undefined)
    0m0.000s


    You can implement missing steps with the snippets below:

    Given("^I have this test\\.$", () -> {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    });

    When("^I test This$", () -> {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    });

    Then("^I get this$", () -> {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    });

But I want the missing steps to be in java like the following :

    @Given("^I have this test\\.$")
    public void I_have_this_test() throws Throwable {
        // Write code here that turns the phrase above into concrete actions
        throw new PendingException();
    }

Can anyone help me how I can achieve this ?

1条回答
戒情不戒烟
2楼-- · 2019-08-14 18:03

You are getting code snippets for Java 8. Please share your dependencies with us.

I would assume that you have a dependency to (using Maven style dependencies)

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java8</artifactId>
    <version>1.2.4</version>
</dependency>

Instead, I think you would like to depend on

<dependency>
    <groupId>info.cukes</groupId>
    <artifactId>cucumber-java</artifactId>
    <version>1.2.4</version>
</dependency>

Update your question with your dependencies from your build tool and we might be able to help you more.

查看更多
登录 后发表回答