The test file can be automatically generated in the class file by right-->go to->test
1. Add Test Notes
Simple method Test
@RunWith (Springrunner.class)
@SpringBootTest
public class Girlservicetest {
@Autowired
Private Girlservice Girlservice;
@Test
public void FindOne () throws Exception {
Girl Girl = Girlservice.findone (30);
Assert.assertequals (New Integer, Girl.getage ()); Assertion
}
}
RESTAPI Test
@RunWith (Springrunner.class)
@SpringBootTest
@AutoConfigureMockMvc
public class Girlcontrollertest {
@Autowired
Private MOCKMVC MVC;
@Test
public void Girllist () throws Exception {
Mvc.perform (Mockmvcrequestbuilders.get ("/girls/list")). Andexpect (Mockmvcresultmatchers.status (). IsOk ())
. Andexpect (Mockmvcresultmatchers.content (). String ("SDF"));
}
}
Packaging commands, CD Girls
MVN Clean packages//package execution Unit tests
MVN clean package-dmaven.test.skip=true//packaging, skipping unit tests
Spring Boot Advanced Web Advanced Learning-Unit Testing