Pregunta

I'm trying to write some Unit and Integration tests for my Spring Controllers following this guide and Spring's documentation for testing MVC controllers

The problem is that I'm unable to find the appropriate includes in mvnrepository for the following piece of code

 this.mockMvc.perform(get("/foo").accept("application/json"))
        .andExpect(status().isOk())
        .andExpect(content().mimeType("application/json"));

I'm unable to find the jar for get("/foo) method and .mimeType(....).

Upon googling, I was however able to find out the source for the above get and mimeType at here. So, should I just copy paste these helper classes from this Spring Test showcase project? or am I missing something here?

¿Fue útil?

Solución 2

I'm assuming you're using Eclipse IDE. Unfortunately it doesn't automatically import static imports.

You have to add these through: Window > Preferences > Java > Editor > Content Assist > Favorites.

Here's a good post with more information:
http://piotrnowicki.com/2012/04/content-assist-with-static-imports-in-eclipse/

Otros consejos

Looks like the package name changed from test.web.server to test.web.servlet in spring-test and the blog articles/docs are out of date for Spring 4.

do you have

 <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-test</artifactId>
        <version>${spring.version}</version>
    </dependency>

somewhere in your pom.xml?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top