【发布时间】:2014-01-07 12:55:53
【问题描述】:
我目前正在试验对 Spring 4.0 中添加的 WebSockets 的支持,如this guide 中所述。如指南中所示,使用 @MessageMapping 注释的方法可以添加到任何 Spring MVC 控制器中,其中也可能包含 @RequestMapping 方法。
spring-test 模块支持以非常简单流畅的方式为@RequestMapping 方法(如here 所述)编写集成测试:
@Test
public void getAccount() throws Exception {
this.mockMvc.perform(get("/accounts/1").accept(MediaType.parseMediaType("application/json;charset=UTF-8")))
.andExpect(status().isOk())
.andExpect(content().contentType("application/json"))
.andExpect(jsonPath("$.name").value("Lee"));
}
是否有类似的支持使用 WebSockets 测试 @MessageMapping 方法?我在任何 Spring 模块中都没有发现任何东西,而且 WebSocket 指南中也没有包含任何测试。如果没有,我是否需要实际部署应用程序并使用WebSocketConnectionManager 连接测试客户端?还是有一些我可以从 spring-test 构建的 API?
This sample project 包含这么小的测试客户端,但我更愿意将它集成到实际测试中,而不需要我在测试中部署应用程序和硬编码部署路径。
【问题讨论】:
标签: java spring spring-mvc spring-test