请考虑以下集成测试。仅以Java为例。
@Test
@WithMockUser
public void givenUnauthorized_whenGettingPeople_thenReturnStatus403() throws Exception {
mvc.perform(get("/v1/api/people"))
.andExpect(status().is(403))
.andExpect(jsonPath("$.success").value(false)) // 1
.andExpect(jsonPath("$.message").value("Access is denied")); // 2
}
您认为评论行1
和2
实际上有帮助吗?我想知道是否应该保留它们。
这是类似的测试:
@Test
public void givenUnauthenticated_whenGettingPeople_thenReturnStatus401() throws Exception {
mvc.perform(get("/v1/api/people"))
.andExpect(status().is(401))
.andExpect(status().reason(containsString("Full authentication is required to access this resource")));
}
我开始认为仅验证401/403
状态就足够了。我说的对吗?