- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我需要测试一个调用异步服务的 Controller 。
Controller 代码
@RequestMapping(value = "/path", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseBody
public ResponseEntity<Result> massiveImport(HttpServletRequest request) {
try {
service.asyncMethod(request);
} catch (Exception e) {
e.printStackTrace();
return new ResponseEntity<>(new Result(e.getMessage()), HttpStatus.BAD_REQUEST);
}
return new ResponseEntity<>(new Result(saveContact.toString()), HttpStatus.OK);
}
@Async
public Future<Integer> asyncMethod(HttpServletRequest request) throws IllegalFieldValueException, Exception {
...
return new AsyncResult<>(value);
}
MvcResult result = getMvc().perform(MockMvcRequestBuilders.fileUpload("/path/")
.header("X-Auth-Token", accessToken)
.accept(MediaType.APPLICATION_JSON))
.andDo(print())
.andReturn();
最佳答案
如果您只想等待异步执行完成,请查看 MvcResult .您可以通过 getAsyncResult()
等待.
使用您当前的代码,您只是在没有任何断言的情况下执行请求。所以测试是不完整的。对于完整的测试,需要以下两个步骤。
首先执行请求:
MvcResult mvcResult = getMvc().perform(fileUpload("/path/")
.header("X-Auth-Token", accessToken)
.accept(MediaType.APPLICATION_JSON))
.andExpect(request().asyncStarted())
.andReturn();
getMvc().perform(asyncDispatch(mvcResult))
.andExpect(status().isOk())
.andExpect(content().contentType(...))
.andExpect(content().string(...));
关于spring-mvc - MockMVC 对异步服务执行后期测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42069226/
总结 我需要在 Camel 服务器 in-modify-out 过程中构建一组统计数据,并将这些统计数据作为一个对象(单个 json 日志行)发出。这些统计数据需要包括: input file met
某个元素使用以下 CSS 功能产生了惊人的结果: 盒子阴影;边界半径;边框和背景上的 RGBA 颜色。 问题是前两个需要延迟 Firefox/Chrome/Safari 浏览器,第二个不兼容 IE8
在我的 Rails 应用程序中有这段代码: window.onload = -> $("#mycontainer").typewriter() $("#div1").fadeIn("slow"
我想检查我的 api 是否工作正常。我有一个只有 post 请求而没有 GET 的 api。 教程在这里:https://learn.microsoft.com/en-us/azure/applica
我想检查我的 api 是否工作正常。我有一个只有 post 请求而没有 GET 的 api。 教程在这里:https://learn.microsoft.com/en-us/azure/applica
我是一名优秀的程序员,十分优秀!