首页>代码>Spring Boot学习(四)之web开发渲染页面 -- Thymeleaf 博客源码>/springbootstudy-demo4-thymeleaf/src/test/java/com/xiaojingg/Springboot4ApplicationTests.java
package com.xiaojingg; import com.xiaojingg.web.HelloController; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.boot.test.SpringApplicationConfiguration; import org.springframework.http.MediaType; import org.springframework.mock.web.MockServletContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders; import static org.hamcrest.Matchers.equalTo; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @RunWith(SpringJUnit4ClassRunner.class) @SpringApplicationConfiguration(classes = MockServletContext.class) @WebAppConfiguration public class Springboot4ApplicationTests { private MockMvc mvc; @Before public void setUp() throws Exception { mvc = MockMvcBuilders.standaloneSetup( new HelloController()).build(); } @Test public void getHello() throws Exception { mvc.perform(MockMvcRequestBuilders.get("/hello").accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) .andExpect(content().string(equalTo("Hello World"))); } }
最近下载更多
lyws1986 LV17
2023年3月9日
wangdengzhe LV7
2022年10月5日
yanghongxiang LV1
2021年9月11日
Jonnydou LV1
2021年6月20日
wangyoung LV10
2021年3月3日
hjd3983 LV10
2020年11月22日
1529860026 LV24
2020年9月15日
lincolnpan LV9
2020年9月2日
mudingc木钉 LV30
2020年5月4日
liuwenlong LV20
2020年3月21日