package club.iyousi.controller; import javafx.application.Application; import org.junit.Assert; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.web.client.TestRestTemplate; import org.springframework.test.context.junit4.SpringRunner; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import java.util.HashMap; import java.util.Map; @RunWith(SpringRunner.class) @SpringBootTest @AutoConfigureMockMvc public class HelloTest { @Autowired private MockMvc mvc; @Test public void listUser() throws Exception { mvc.perform(MockMvcRequestBuilders.get("/users")) .andExpect(MockMvcResultMatchers.status().isOk())//通过 .andExpect(MockMvcResultMatchers.content().string("[]"));//期望结果是一个值 } @Test public void post() throws Exception { mvc.perform(MockMvcRequestBuilders.post("/users").param("id","1").param("name","sfz").param("age","12")) .andExpect(MockMvcResultMatchers.status().isOk())//通过 .andExpect(MockMvcResultMatchers.content().string("success"));//期望结果是一个值 } }