我一直在拼命試圖解決一個黃瓜Junit步驟執行。黃瓜JUNIT步驟執行忽略
我只是跟着限定特徵,測試和步驟如下的一個簡單的例子:
Feature: Campaign Budget Calculation
Scenario: Valid Input Parameters
Given campaign budget as 100 and campaign amount spent as 120
When the campaign budget is less than campaign amount spent
Then throw an Error
測試:
@RunWith(Cucumber.class)
@Cucumber.Options(glue = { "com.reachlocal.opt.dbas" })
public class CampaignTest {
}
步驟:
public class CampaignTestStepDefinitions {
private Campaign campaign;
@Given("^a campaign with (\\d+) of budget and (\\d+) of amount spent$")
public void createCampaign(int arg1, int arg2) throws Throwable{
CurrencyUnit usd = CurrencyUnit.of("USD");
campaign = new Campaign();
campaign.setCampaignBudget(Money.of(usd, arg1));
campaign.setCampaignAmountSpent(Money.of(usd, arg2));
}
@When("^compare the budget and the amount spent$")
public void checkCampaignBudget() throws Throwable{
if (campaign.getCampaignBudget().isLessThan(campaign.getCampaignAmountSpent())) {
campaign.setExceptionFlag(new Boolean(false));
}
}
@Then("^check campaign exception$")
public void checkCampaignException() throws Throwable{
if (campaign.getExceptionFlag()) {
assertEquals(new Boolean(true), campaign.getExceptionFlag());
}
}
}
當運行junit,跳過這些步驟,結果顯示它們全部被忽略。我以前沒有使用過膠水,但沒有幫助。 不知道爲什麼。來自Internet的簡單示例代碼(如添加2個數字)工作正常。 我在使用STS的Maven/Spring項目中運行它。