Interfacetest, you can see in the Testmain is the basic method of implementing test test.
The code is as follows:
Public classInterfacetest {Final StaticString param = "param"; Htmlfile HF=NewHtmlfile (); Public voidtest1 (String p_paramcontent, String p_description, String p_url) {LongStartTime =System.currenttimemillis (); String resultstring= ""; String msg=p_paramcontent; Jsonobject JsonObject1=NULL; Try{JsonObject1=Newjsonobject (msg); } Catch(jsonexception E1) {//TODO auto-generated Catch blockE1.printstacktrace (); } Map<string, string> DataMap =NewHashmap<string, string>(); Datamap.put (param, jsonobject1.tostring ()); Try{resultstring=Newhttputil (). DoPost (P_url, DATAMAP); Jsonobject Jsonobject=NewJsonobject (resultstring); String resultstatues= Jsonobject.getstring ("Success"); if(Resultstatues! =NULL&& resultstatues! = "") { if(Resultstatues.equalsignorecase ("true")) { //Output LogHf.write (P_description, changeresultstring (resultstring), "true"); } Else{hf.write (p_description, changeresultstring (resultstring),"False"); } } Else{hf.write (p_description, changeresultstring (resultstring),"False"); } } Catch(Exception e) {//TODO auto-generated Catch blockE.printstacktrace (); Hf.write (P_description, changeresultstring (resultstring),"False"); } } Public voidtest2 (String p_paramcontent, String p_description, String p_url) {LongStartTime =System.currenttimemillis (); String resultstring= ""; String msg=p_paramcontent; Jsonobject JsonObject1=NULL; Try{JsonObject1=Newjsonobject (msg); } Catch(jsonexception E1) {//TODO auto-generated Catch blockE1.printstacktrace (); } Map<string, string> DataMap =NewHashmap<string, string>(); Datamap.put (param, jsonobject1.tostring ()); Try{resultstring=Newhttputil (). DoPost (P_url, DATAMAP); Jsonobject Jsonobject=NewJsonobject (resultstring); String resultstatues= Jsonobject.getstring ("Success"); if(Resultstatues! =NULL&& resultstatues! = "") {hf.write (p_description, changeresultstring (resultstring),"True"); } Else{hf.write (p_description, changeresultstring (resultstring),"False"); } } Catch(Exception e) {//TODO auto-generated Catch blockE.printstacktrace (); Hf.write (P_description, changeresultstring (resultstring),"False"); } } Public Staticstring changeresultstring (String p_resultstring) {StringBuilder resultstring=NewStringBuilder (); if(P_resultstring! = "" && p_resultstring! =NULL) { if(P_resultstring.length () > 70) {resultstring.append (p_resultstring.substring (0, 70)); Resultstring.append ("..."); } Else{resultstring.append (p_resultstring); } } Else{resultstring.append ("Return value is null"); } returnresultstring.tostring (); }}
It contains three methods
1. Test1 () and Test2 () are in fact the same method, but the intermediate judgments differ in the way they are, because some interfaces use the success field = = True to determine success, and some are not.
2. Test1 () or test2 (), use the Httputil (). Dopost method to obtain the interface returned by the server, which matches whether the success value equals True or FALSE to determine whether the interface passed.
3. The way to output the log is to write the results into HTML using the Write method in Htmlfile.
4. The changeresultstring () method, which is used to intercept the length in the return value, displays an ellipsis if the length is too long.
Interface testing-automated-java implementation-interfacetest