---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