我一直在拼命尝试解决 Cucumber 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 项目中运行它。