spring boot1.5.6 测试类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了spring boot1.5.6 测试类相关的知识,希望对你有一定的参考价值。
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 测试类的主要内容,如果未能解决你的问题,请参考以下文章
为啥在测试类中设置的 spring.profiles.active 在实际测试类的环境属性中不可用?