I have been desperately trying to resolve a Cucumber Junit step execution.
I just followed a simple example of defining a feature, test and steps as below:
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
Test:
@RunWith(Cucumber.class)
@Cucumber.Options(glue = { "com.reachlocal.opt.dbas" })
public class CampaignTest {
}
Steps:
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());
}
}
}
When I run the junit, the steps are skipped, and the results shows they are all ignored. I have tried without glue as well before but does not help. Not sure why. Simple Example code from the Internet like adding 2 numbers are working fine. I'm running it in Maven/Spring project using STS.