我想获得有关如何为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)格式时增加了测试的可读性。 –