我正在尝试运行用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/
功能:根据实数列表计算总数
场景:计算实数列表的总和
给出实数列表
|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 {
}