2016-04-10 30 views
0

爪哇 - 黃瓜例如JUnit的黃瓜缺少的步驟錯誤

貌似我缺少的步驟,它抱怨缺少的步驟和考慮它們爲未定義

.feature文件:

Feature: Roman Feature 

    Scenario: Convert Integer to Roman Number 
    Given I am on the demo page 
    When I pass number 1 
    Then the roman result is I 


    Scenario: Convert Integer to Roman Number 
    Given I am on the demo page 
    When I pass number 5 
    Then the roman result is V 

步驟文件:

@When("^I pass number (\\d+)$") 
    public void convert_numbers_to_roman(int arg1) throws Throwable { 
     // convert number 

    } 



@Then("^the roman result is (\\d+)$") 
    public void the_roman_result_is(int result) throws Throwable { 
     // match result 
    } 

當我運行測試

Scenario: Convert Integer to Roman Number [90m# net/xeric/demos/roman.feature:3[0m 
    [32mGiven [0m[32mI am on the demo page[0m    [90m# DemoSteps.i_am_on_the_demo_page()[0m 
    [32mWhen [0m[32mI pass number [0m[32m[1m1[0m     [90m# DemoSteps.convert_numbers_to_roman(int)[0m 
    [33mThen [0m[33mthe roman result is I[0m 

6情景2未定義 您可以實現失蹤與下面的代碼片段步驟:

@Then("^the roman result is I$") 
public void the_roman_result_is_I() throws Throwable { 
    // Write code here that turns the phrase above into concrete actions 
    throw new PendingException(); 
} 
+0

當問題中沒有顏色控制檯格式時,很感激。在你的配置中使用'monochrome = true'。 –

回答

1

我會考慮醒目的羅馬數字作爲一個字符串,因此使用正則表達式

then步驟是這樣的(*):

@Then("^the roman result is (.*)$") 
public void the_roman_result_is_I(String expectedRoman) throws Throwable { 
    // Write code here that turns the phrase above into concrete actions 
    throw new PendingException(); 
} 

這類似於塞巴斯蒂安答案,但在我看來,更簡單的正則表達式。它捕獲任何字符串並將其作爲參數傳遞。

您可能會在步驟中執行的斷言會告訴您是否有某些內容被損壞。對失敗的斷言進行故障排除可能比排除失敗的步驟更容易。

0

的問題是在你的正則表達式 - \d將只匹配阿拉伯數字(這是\\d在Java中,ESE) 。

你真正想要的是^the roman result is ([IVMCLX]+)$。這將匹配一個或多個羅馬數字字符,將結果粘貼到您選擇的字符串中。