我想獲得有關如何爲Rest API進行集成測試的不同觀點。Rest API的集成測試
第一種選擇將使用黃瓜在「黃瓜書」如所描述的:使用黃瓜(再次)
Scenario: Get person
Given The system knows about the following person:
| fname | lname | address | zipcode |
| Luca | Brow | 1, Test | 098716 |
When the client requests GET /person/(\d+)
Then the response should be JSON:
"""
{
"fname": "Luca",
"lname": "Brow",
"address": {
"first": "1, Test",
"zipcode": "098716"
}
}
"""
第二個方案是,但去除技術詳細描述here:
Scenario: Get person
Given The system knows about the following person:
| fname | lname | address | zipcode |
| Luca | Brow | 1, Test | 098716 |
When the client requests the person
Then the response contains the following attributes:
| fname | Luca |
| lname | Brow |
| address :first | 1, Test |
| address :zipcode | 098716 |
和Th Ë第三種選擇是使用春描述here:
private MockMvc mockMvc;
@Test
public void findAll() throws Exception {
mockMvc.perform(get("/person/1"))
.andExpect(status().isOk())
.andExpect(content().mimeType(IntegrationTestUtil.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$.fname", is("Luca")))
.andExpect(jsonPath("$.lname", is("Brow")))
.andExpect(jsonPath("$.address.first", is("1, Test")))
.andExpect(jsonPath("$.address.zipcode", is("098716")));
}
我真的很喜歡,因爲它看起來更清潔企業用戶和測試者的第二選擇,但另一方面也爲開發者將消耗該API的第一個選項看起來更可見,因爲它顯示了JSON響應。
第三個選項是最簡單的選擇,因爲它只是Java代碼,但可讀性和跨團隊交互不如黃瓜好。
你BDD的定義不正確,BDD測試的行爲,或軟件的公共接口,在這種情況下是應用程序公開的端點。同樣,BDD在使用GWT(Given-When_then)格式時增加了測試的可讀性。 –