码迷,mamicode.com
首页 > 编程语言 > 详细

spring boot1.5.6 测试类

时间:2017-10-24 17:20:08      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:one   col   com   builder   web   text   with   span   ram   

package com.qutaoyao.demo.web;

import com.qutaoyao.demo.web.controller.HelloController;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;


@RunWith(SpringRunner.class)
@SpringBootTest
public class HelloControllerTests {

private MockMvc mvc;

@Before
public void init(){
this.mvc = MockMvcBuilders.standaloneSetup(new HelloController()).build();
}

@Test
public void sayHi() throws Exception{
RequestBuilder req = get("/hello/hi");

mvc.perform(req).andExpect(status().isOk()).andExpect(content().string("Hello World!."));
}
}

spring boot1.5.6 测试类

标签:one   col   com   builder   web   text   with   span   ram   

原文地址:http://www.cnblogs.com/faunjoe88/p/7724288.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!