首页>代码>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日
最近浏览更多
skook7  LV2 2023年12月14日
zhaozhiqi  LV5 2023年10月19日
ewan007  LV29 2023年7月7日
森sdfgf  LV8 2023年6月11日
刘春涛  LV2 2023年6月5日
lyws1986  LV17 2023年3月9日
yohohero  LV1 2023年1月14日
wangdengzhe  LV7 2022年10月5日
win1991  LV6 2022年8月18日
anopsign  LV1 2022年6月30日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友