Spring mvc控制器测试+ Json响应错误

时间:2013-05-28 03:47:35

标签: spring testing spring-mvc

我的春天mvc测试控制器:

@Test
public void consultaPorIdJson() throws Exception{
    mockMvc.perform(get("/timesheet/consultaporidjson/{id}", 1L))
            .andExpect(status().isOk())
            .andExpect(content().contentType(TestSupport.APPLICATION_JSON_UTF8))
            .andExpect(content().string("{\"id\":1,\"latitude\":\"30.448660206791608\",\"longitude\":\"-44.29684999999995\"}"));

当我尝试运行测试时出现错误:

java.lang.IllegalStateException: Cannot set error status - response is already committed

我认为这是约2k(我认为)的回应,但我不知道我该怎么做才能解决它: - (

1 个答案:

答案 0 :(得分:0)

网址是否在您的测试之外?我怀疑它不起作用,因为错误表明你的实现中存在问题,代码试图在响应中写入某些内容时尝试更改状态。

相关问题