Springboot automatic generation of test cases

Source: Internet
Author: User

---restore content starts---

@SpringBootTest Note is an annotation for testing that was introduced by Springboot since the 1.4.0 version

1. Add Maven Dependencies

<dependency>

  <groupid>org.springframework.boot</groupid>

<artifactid>spring-boot-starter-test</artifactid>

</dependency>

2.Controller Right-->new A test case, select the method you want to generate the cases, click Finish.

3. Using MOCKMVC for unit testing, MOCKMVC is the only one that supports controller testing.

The test classes are as follows:


Private MOCKMVC Mockmvc;

@Autowired
Private Webapplicationcontext Webapplicationcontext;

@Before
public void init () {
MOCKMVC = Mockmvcbuilders.webappcontextsetup (webapplicationcontext). build ();
}

Secret secret key
Final String salt = "11";
Final String key = "Miyao";

public static final Charset Charset_utf8 = Charset.forname ("UTF-8");

@Test
public void Testregister () {
Fail ("not yet implemented");
Uusregisterreq req = new Uusregisterreq ();
Req.setparterkey ("KE");
Req.setpartersource (2);
Req.setparteruesrid ("1");
Req.setphone ("13122221111");
String str = Fastjsonutils.obj2json (req);
Requestbuilder Requestbuilder = Mockmvcrequestbuilders.post ("/uus/register"). Content (str)
. ContentType (Mediatype.application_json);
try {
String res = Mockmvc.perform (requestbuilder). Andexpect (Mockmvcresultmatchers.status (). IsOk ()). Andreturn ()
. GetResponse (). getcontentasstring ();
Log.info ("Registration test result: {}", res);
} catch (Exception e) {
E.printstacktrace ();
}
}

Springboot automatic generation of test cases

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.