The first time to send a blog, but also ask you a lot of advice.
Currently in the project is separated from the front and back, using wiremock data, but the interface is generally driven by the background (version manager in the background). Many times the background changes the interface often did not inform the foreground, resulting in a frequent interface error, and many times there is a dependency between the interfaces, if the previous interface can not test the subsequent interface is not able to proceed. Based on this, it is necessary to develop a set of methods that can automatically test the interface.
Directly on the code, Testportforconsole.js:
var postdatas = [{url: '/getstudents.do ', portname: ', Description: ', data:{ ServiceName: "Getstudents", Class: "Six", Grade: "Both"}, {URL: "/get Score.do ", PortName: ', Description: ', data:{serviceName:" Getscore ", Stude Ntid: "08070146", Subject: "Math"}}
Each of these elements corresponds to an interface];(function () {Localstorage.removeitem (' success '); Localstorage.removeitem (' failed '); var send = function (url,param,portname) {$.ajax ({url:url, type: ' POST ', data:j Son.stringify (param), DataType: ' application/json,text/plain.*/* '}). Success (function (data) { Localstorage.setitem (' Success ', Localstorage.getitem (' success ') + PortName + ' interface return success | '); }). Error (function (data) {Localstorage.setitem (' failed ', Localstorage.getitem (' failed ') + PortName + ' interface return failed | ') ; Throw PortName + ' interface return failed '; }) }; for (var s = 0,len = Postdatas.length;s < len;s++) {send (Postdatas[s].url,postdatas[s].data, Postdatas[s].portnam e); }})();
If there are too many interfaces, consider using the grunt command to merge the mock data from each of the issued requests from the project, which facilitates sub-module maintenance and management.
Module.exports = function (grunt) { //project configuration grunt.initconfig ({ Pkg:grunt.file.readJSON (' Package.json '), concat: { options: { banner: ' [\ n ', separator: ', \ n ', footer: '] ', stripbanners: ' True ' }, build: { src: ' Src/**/*.json ', dest: ' Dest/dest.json '}}} ); Grunt.loadnpmtasks (' Grunt-contrib-concat '); Grunt.registertask (' Default ', [' concat ']);}
This can be done directly in the original project directly in the Testportforconsole.js code copy run to automatically complete the interface scan. The results of the scan are saved in localstorage and can be obtained by the following methods
Console.dir (Localstorage.getitem (' success '). Split (' | '));
Console.dir (Localstorage.getitem (' failed '). Split (' | '));
Novice seeking support ~_~.
Web front-end automatic interface scanning