1
我在Eclipse中有一個小的cucumber-JUnit示例,我可以成功運行。之後,我重新命名了Package的名稱,並稍稍使用了代碼。但現在抱怨說: -在黃瓜中找不到步驟定義java
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 = {"[email protected]"},
//glue = {"src/test/java/cucumber/junit/maven/cucumber_jvm/maven"}
glue = {"src/test/java/cucumber/junit/test"}
)
public class RunCalculatorTest {
}
我仔細檢查了路徑膠水,它是正確的。我也更新了我的項目並完成了mvn clean install。有人能指出爲什麼沒有找到stepdefinition?
嘗試將'glue'選項更改爲:'glue = {「cucumber.junit.test」}'或'glue =「cucumber.junit.test」'。我認爲它正在尋找一個軟件包名稱。 –
正是這個問題。感謝您的超級快速回答。你可以將它作爲答案發布,然後我將接受它作爲答案。我仍然想知道它什麼時候需要路徑和包名。因爲早些時候它已經成功地使用了路徑。 – Ragini
應該使用路徑,你可以試試'glue =「src/test/java/cucumber.junit.test」'? –