2017-09-27 108 views
0

我是Cucumber測試框架的新手,我應該使用黃瓜來測試REST API。我們可以說有一個REST API和端點http://localhost:8080/REST/coffee/search ,並接受三個查詢參數「type」,「toppings」和「cost」。有幾個組合的查詢參數是可能的。編寫用於測試REST API的黃瓜場景

我的問題是在寫作場景來測試這個API。我想通過使用這些查詢參數的幾個組合來調用API。 但我在使用數據表或方案大綱之間感到困惑。

With Data Tables: //data is sent inside StepDefinition method as Data Table 

    Scenario: User Searches for Coffee 
     Given Coffee exists with valid data 
     |type   |toppings  | cost    | 
     |Latte  |    |  1    | 
     |Espresso  |Whipped Cream |  2    |  
     |Espresso  |    |  3.5   | 
     When User call the API with given data 
     Then Verify API Response for status 

With Scenario Outline: // data is sent to individual params of stepdefinition. 

    Scenario Outline: User Searches for Coffee 
     Given Coffee exists with valid data <type>, <toppings>, <cost> 
     When User call the API with given data 
     Then Verify API Response for status 

    Examples: 

     |type   |toppings  | cost    | 
     |Latte  |    |  1    | 
     |Espresso  |Whipped Cream |  2    |  
     |Espresso  |    |  3.5   | 

是否可以在場景大綱中獲取數據表,如果我嘗試類似下面的內容?

Scenario Outline: User Searches for Coffee 
     Given Coffee exists with valid data 
     When User call the API with given data 
     Then Verify API Response for status 

    Examples: 

     |type   |toppings  | cost    | 
     |Latte  |    |  1    | 
     |Espresso  |Whipped Cream |  2    |  
     |Espresso  |    |  3.5   | 



Since I have 10+ query params to use, Please suggest some best practices too.  

回答

0

你最好寫一個單元測試來做這種測試。然後,您可以將查詢參數存儲在數據結構中並對其進行迭代。

0

你的要求不是從你的問題完全明確,但也許你正在尋找的是可以使用的示例數據還步驟裏面的數據表:

Scenario Outline: User Searches for Coffee 
    Given Coffee exists with: 
    | type | toppings | cost | 
    | <type> | <topping> | <cost> | 
    When User call the API with given data 
    Then Verify API Response for status 
Examples: 
    | type   | topping  | cost | 
    | Latte  |    | 1 | 
    | Espresso  | Whipped Cream | 2 |  
    | Espresso  |    | 3.5 |