Created
February 25, 2017 21:05
-
-
Save javaeeeee/eaf144cfa043615ffeb9194fe54c214e to your computer and use it in GitHub Desktop.
A Spring MVC REST controller test for a Spring Boot application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.javaeeeee.controllers; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | |
import org.springframework.boot.test.context.SpringBootTest; | |
import org.springframework.test.context.junit4.SpringRunner; | |
import org.springframework.test.web.servlet.MockMvc; | |
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | |
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | |
@RunWith(SpringRunner.class) | |
@SpringBootTest | |
@AutoConfigureMockMvc | |
public class HelloControllerTest { | |
@Autowired | |
private MockMvc mockMvc; | |
@Test | |
public void getGreeting() throws Exception { | |
this.mockMvc.perform(get("/hello")) | |
.andExpect(status().isOk()) | |
.andExpect(content().string("Hello Spring World!")); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment