2013-07-12 98 views
1

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

回答

0

试试这个,

import org.junit.runner.RunWith; 

import cucumber.api.junit.Cucumber; 

@RunWith(Cucumber.class) 
@Cucumber.Options(format = { "json:target/REPORT_NAME.json", "pretty", 
    "html:target/HTML_REPORT_NAME" }, features = { "src/test/resources/PATH_TO_FEATURE_FILE/NAME_OF_FEATURE.feature" }) 
public class Run_Cukes_Test { 

} 

这一直是为我工作。

1

@Given,@When和@Then表达式与特征文件不匹配。它们是正则表达式,需要匹配特征文件中的行。

例如,对于特征线:

鉴于活动预算为100和竞选花费的金额为120

中的步骤

文件,你已经有了:

@Given(“^ a预算为(\ d +)的广告系列((d +)金额为 )$

,但它应该是:

那么就应该匹配,并且

@Given( “花为 (\ d +)$ ^竞选预算(\ d +)和活动量”)不要忽视这一步。

刚刚有同样的问题,在Eclipse中很容易错过,因为您仍然会得到一个绿色的勾号,尽管它确实表示它们被忽略。

0

我也得到了同样的错误,事实证明,在所有的步骤定义的方法是的公共

私人代替