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!."));
}
}

相关文章:

  • 2022-12-23
  • 2021-07-11
  • 2021-12-22
  • 2021-11-23
  • 2022-01-06
  • 2022-12-23
  • 2021-07-22
猜你喜欢
  • 2022-01-12
  • 2021-10-14
  • 2021-12-09
  • 2021-04-27
  • 2021-07-20
  • 2021-10-01
  • 2021-10-11
相关资源
相似解决方案