2017-09-27 62 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 |