首页>代码>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")));
	}
}
 最近下载更多
最近下载更多
                
                shuangfu     LV25
                2024年4月26日
            
            
        
                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日
            
            
         最近浏览更多
最近浏览更多
                
                renjunyou     LV10
                6月2日
            
            
        
                hkxyyz     LV6
                3月25日
            
            
        
                xinshou11111x    
                2024年12月12日
            
            
                    暂无贡献等级
            
        
                fei3655     LV6
                2024年10月16日
            
            
        
                y1214435276     LV9
                2024年9月26日
            
            
        
                微信网友_7134912998903808     LV15
                2024年8月29日
            
            
        
                599142776     LV2
                2024年8月13日
            
            
        
                ma406805131     LV19
                2024年6月15日
            
            
        
                f22m1a2b2     LV17
                2024年5月31日
            
            
        
                子夜青创    
                2024年5月4日
            
            
                    暂无贡献等级
            
        
 
                 
                 
    