首页 > 解决方案 > cucumber.runtime.CucumberException:调用 stepDefinition 失败

问题描述

我正在尝试运行用 java 编写的黄瓜测试。

但我不能,因为代码无法调用stepDefinition

cucumber.runtime.CucumberException: Failed to invoke stepDefinition.TotalListNumber.a_list_of_real_numbers(Double>) in file:/C:/Users/DELL/eclipse-workspace/TotalListNumber/target/classes/

Eclipse 异常

功能:从实数列表中计算总数
场景:计算实数列表的总和

给定一个实数列表

        |25.0|
        |1500.0|
        |580.0|
        |600.0|

我计算它们的总和时,我会得到 2705.0

package stepDefinition;

import org.hamcrest.CoreMatchers;
import com.sun.tools.javac.util.Assert;
import com.sun.tools.javac.util.List;
import static org.junit.Assert.assertThat;
import cucumber.api.java.en.Given;
import cucumber.api.java.en.Then;
import cucumber.api.java.en.When;

public class TotalListNumber {
    private double sum;
    private List<Double> numbers;
    @Given("^a list of real numbers$")
    public void a_list_of_real_numbers(List<Double> numbers) throws Throwable {
        this.numbers = numbers;
    }
    @When("^I calculate the sum of them$")
    public void I_calculate_the_sum_of_them() throws Throwable {
        for (Double number : numbers) {
            sum += number;
        }
    }
    @Then("^I will get (\\d+\\.\\d+)$")
    public void I_will_get_(Double expectedTotal) throws Throwable {
        assertThat(sum, CoreMatchers.is(expectedTotal));
        System.out.println("Actual Sum : " + sum);
    }
}
package Runner;

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

@RunWith(Cucumber.class)
@CucumberOptions(
    features = {"C:\\Users\\DELL\\eclipse-workspace\\TotalListNumber\\src\\main\\java\\Features\\TotalListNumber.feature" },
    glue = "stepDefinition",
    monochrome = true,
    plugin = {"pretty", "html:target/cucumber", "json:target/Cucumber.json", "junit:target/Cucumber.xml"
    })
public class TestRunner {

}

标签: javacucumber

解决方案


推荐阅读