简体   繁体   English

在黄瓜java中找不到步骤定义

[英]Step Definition not found in Cucumber java

I have a small cucumber-JUnit example in Eclipse which I could run successfully. 我在Eclipse中有一个小黄瓜JUnit示例,可以成功运行。 After that I renamed the Package name and played around with the code a bit. 之后,我重命名了Package名称,并使用了一些代码。 But now it complains that:- 但现在它抱怨:

Feature: Calculator
  I use Calculator instead of calculating myself

  @smokeTest
  Scenario Outline: Add two numbers # src/test/java/cucumber/junit/test/calculatorFeature.feature:17
    Given I have a calculator
    When I add 2 and 3
    Then the result should be 5

  @smokeTest
  Scenario Outline: Add two numbers # src/test/java/cucumber/junit/test/calculatorFeature.feature:18
    Given I have a calculator
    When I add 4 and 5
    Then the result should be 9

  @regressionTest
  Scenario: Subtract one number from another # src/test/java/cucumber/junit/test/calculatorFeature.feature:21
    Given I have a calculator
    When I subtract 2.5 from 7.5
    Then the result should be 5.0

3 Scenarios (3 undefined)
9 Steps (9 undefined)
0m0,000s


You can implement missing steps with the snippets below:

@Given("^I have a calculator$")
public void i_have_a_calculator() throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^I add (\\d+) and (\\d+)$")
public void i_add_and(int arg1, int arg2) throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^the result should be (\\d+)$")
public void the_result_should_be(int arg1) throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@When("^I subtract (\\d+)\\.(\\d+) from (\\d+)\\.(\\d+)$")
public void i_subtract_from(int arg1, int arg2, int arg3, int arg4) throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

@Then("^the result should be (\\d+)\\.(\\d+)$")
public void the_result_should_be(int arg1, int arg2) throws Throwable {
    // Write code here that turns the phrase above into concrete actions
    throw new PendingException();
}

My Runner looks like: 我的跑步者看起来像:

package cucumber.junit.test;

import cucumber.api.CucumberOptions;
import cucumber.api.junit.Cucumber;
import org.junit.runner.RunWith;

@RunWith(Cucumber.class)
@CucumberOptions(

        features = "src/test/java/cucumber/junit/test/calculatorFeature.feature",
        //This executes all the scenarios tagged as smokeTest and regressionTest
        format = {"pretty", "html:target/cucumber"}, tags = {"@smokeTest,@regressionTest"},
        //This will execute all the scenarios except those tagged as smokeTest
        // tags = {"~@smokeTest"},
        //glue = {"src/test/java/cucumber/junit/maven/cucumber_jvm/maven"}     
        glue = {"src/test/java/cucumber/junit/test"}

    )
    public class RunCalculatorTest {    

    }   

在此处输入图片说明

I have checked the path to the glue carefully and it is correct. 我已经仔细检查了胶水的路径,它是正确的。 I have also updated my project and done mvn clean install. 我还更新了我的项目,并完成了mvn全新安装。 Could someone please point out why is it not finding stepdefinition ? 有人可以指出为什么找不到逐步定义吗?

Glue option is probably looking for a package name. 胶水选项可能正在寻找包装名称。 Try this: 尝试这个:

glue = {"cucumber.junit.test"}

or 要么

glue = "cucumber.junit.test"

Check out this post , it's a bit old but should get you started in no time. 看看这篇文章 ,它有点陈旧,但是应该很快就可以开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM