简体   繁体   English

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

[英]Spring mvc controller test + Json response error

I have in my spring mvc test controller: 我的春季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\"}"));

When I trying to run my test I get an error: 当我尝试运行测试时,出现错误:

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

I think that is about 2k (I think) of response, but I don't know what must I do to fix it :-( 我认为这大约是2k(我认为),但我不知道该如何解决:-(

Does the url works outside of your test? 网址在您的测试之外有效吗? I doubt it does not work as the error suggests you have issue in your implementation where the code is trying to change the status when something is already written in the response. 我怀疑它不起作用,因为错误表明您的实现中存在问题,当响应中已写入某些内容时,代码试图更改状态。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM