java - 在 Cucumber java 中找不到步骤定义

标签 java junit cucumber bdd

我在 Eclipse 中有一个小的 cucumber-JUnit 示例,我可以成功运行它。之后,我重命名了包名称并稍微修改了代码。但现在它提示说:-

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();
}

我的运行者看起来像:

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 {    

    }   

enter image description here

我仔细检查了胶水的路径,是正确的。我还更新了我的项目并完成了 mvn clean install。有人可以指出为什么找不到 stepdefinition 吗?

最佳答案

Glue 选项可能正在寻找包名称。试试这个:

glue = {"cucumber.junit.test"}

glue = "cucumber.junit.test"

看看这个 post ,它有点旧,但应该可以让您立即入门。

关于java - 在 Cucumber java 中找不到步骤定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45565840/

相关文章:

ruby-on-rails - 如何使用 Cucumber 或 rspec 测试 RSS 提要

api - 如何在 Karate 中复制节点及其子节点

java - 调试JVM崩溃(如何找到底层C代码中的错误?)

javascript - Angular http post 请求 - 请求的资源上不存在 'Access-Control-Allow-Origin' header

java - 是否可以在不重写整个文件的情况下以编程方式更新 Jar 文件?

java - 公开 junit 的虚拟 URL

java - @Before 没有为 @Test 实例化我的对象

java - 想要并行运行 Apache Beam Pipeline

java - 配置 Ant 使用 JUnit 4

ruby - 在步骤定义中调用步骤