Spring Boot Advanced Web Advanced Learning-Unit Testing

Source: Internet
Author: User
Tags findone

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.