2013-07-12 97 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

我也得到了同樣的錯誤,事實證明,在所有的步驟定義的方法是的公共

私人代替