title: Testing @MessageMapping WebSocket methods of Spring MVC controllers
body: <p>I am currently experimenting with the support for WebSockets added in Spring 4.0, as described in <a href="http://spring.io/guides/gs/messaging-stomp-websocket/" rel="nofollow">this guide</a>. As demonstrated in the guide, methods annotated with <code>@MessageMapping</code> can be added to any Spring MVC controller, which may also contain <code>@RequestMapping</code> methods.</p>
  
  <p>The spring-test module has support for writing integration tests for <code>@RequestMapping</code> methods (as described <a href="http://docs.spring.io/spring/docs/4.0.0.RELEASE/spring-framework-reference/html/testing.html#spring-mvc-test-framework" rel="nofollow">here</a>) in a very simple and fluid way:</p>
  
  <pre><code>@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"));
  }
  </code></pre>
  
  <p>Is there similar support for testing <code>@MessageMapping</code> methods using WebSockets? I have not found anything in any of the Spring modules, and none of the WebSocket guides contain any tests. If not, would I need to actually deploy the application and use a <a href="http://docs.spring.io/autorepo/docs/spring/4.0.0.RELEASE/javadoc-api/org/springframework/web/socket/client/WebSocketConnectionManager.html" rel="nofollow"><code>WebSocketConnectionManager</code></a> to connect a test client? Or is there some API I can build on from spring-test?</p>
  
  <p><a href="https://github.com/rstoyanchev/spring-websocket-test/blob/master/src/test/java/org/springframework/samples/websocket/echo/StandardClientApp.java" rel="nofollow">This sample project</a> contains such a small test client, but I would prefer to integrate this into the actual tests without requiring me to deploy the application and hardcode the deployed path in the tests.</p>