mirror of
https://github.com/ityouknow/spring-boot-examples.git
synced 2026-09-03 07:27:38 +08:00
37 lines
1.3 KiB
Java
37 lines
1.3 KiB
Java
package com.neo.controller;
|
|
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
|
import org.springframework.http.MediaType;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
import org.springframework.test.web.servlet.MockMvc;
|
|
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
|
import org.springframework.test.web.servlet.result.MockMvcResultHandlers;
|
|
|
|
|
|
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(SpringRunner.class)
|
|
@WebMvcTest(HelloWorldController.class)
|
|
public class HelloTests {
|
|
|
|
@Autowired
|
|
private MockMvc mvc;
|
|
|
|
@Test
|
|
public void getHello() throws Exception {
|
|
mvc.perform(MockMvcRequestBuilders
|
|
.get("/hello")
|
|
.accept(MediaType.APPLICATION_JSON))
|
|
.andExpect(status().isOk())
|
|
.andDo(MockMvcResultHandlers.print())
|
|
.andExpect(content()
|
|
.string(equalTo("Hello World")));
|
|
}
|
|
|
|
} |