Package Com.example.demo;
Import Org.junit.Before;
Import Org.junit.Test;
Import Org.junit.runner.RunWith;
Import Org.springframework.boot.test.context.SpringBootTest;
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 Org.springframework.test.web.servlet.result.MockMvcResultMatchers;
Import Org.springframework.test.web.servlet.setup.MockMvcBuilders;
Import Com.example.demo.controller.HelloWorldController;
@RunWith (Springrunner.class)
@SpringBootTest
public class Helloworldcontrolertests {
Private MOCKMVC MVC;
@Before
public void SetUp () throws Exception {
MVC = Mockmvcbuilders.standalonesetup (New Helloworldcontroller ()). build ();
}
@Test
public void Gethello () throws Exception {
Mvc.perform (Mockmvcrequestbuilders.get ("/sayhello"). Accept (Mediatype.application_json))
. Andexpect (Mockmvcresultmatchers.status (). IsOk ())
. Anddo (Mockmvcresulthandlers.print ())
. Andreturn ();
}
}
Spring boot1.5.6 Test Class 1