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?
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.
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/
do you have
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<version>${spring.version}</version>
</dependency>
somewhere in your pom.xml?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With