???????????API??????????
???????????? ???????[ 2017/1/9 10:22:42 ] ????????API??? ???????
?????????????У???????????????????? utils.js ?е? test ???????÷????????????????????????????????????????????????????????? test ?????????????????????????????е???ν?????£?
????agent?????? API ??????
????file????????????????????
????group????????????????
????title???????????
????method???????????
????params?????????????????
????headers: ??????????е??????
????expect??supertest ??expect??
????callback??supertest ?????? end ??????????
????utils.js???????£?
// utils.js
const path = require('path');
const fs = require('fs');
const mdStr = {};
exports.test = function(obj){
if (!mdStr[obj.group]) {
mdStr[obj.group] = '';
mdStr[obj.group] += '## ' + obj.group + ' ';
}
const fields = {};
mdStr[obj.group] += `###${ obj.title }`${ obj.method }`${ obj.url } #### ???? `;
mdStr[obj.group] += ' ?????? | ???? | ?????? | ??? -----|-----|-----|----- ';
Object.keys(obj.params).forEach(function(param){
const paramVal = obj.params[param];
fields[param] = paramVal['value'];
mdStr[obj.group] += `${ param }|${ paramVal['type'] }|${ paramVal['required'] ?'??':'??'}|${ paramVal['desc'] } `;
});
mdStr[obj.group] += ' #### ?????? ???????: ';
mdStr[obj.group] += '```json ' + JSON.stringify(fields?? null?? 2) + ' ``` ';
mdStr[obj.group] += ' ??????: ';
if (obj.url.indexOf(':') > -1) {
obj.url = obj.url.replace(/:w*/g?? function(word){
return fields[word.substr(1)];
});
}
obj.agent[obj.method](obj.url)
.set(obj.header || {})
.query(fields)
.send(fields)
.expect(obj.expect)
.end(function(err?? res){
mdStr[obj.group] += '```json ' + JSON.stringify(res.body?? null?? 2) + ' ``` ';
mdStr[obj.group] += ' ';
if (process.env['GEN_DOC'] > 0) {
fs.writeFileSync(path.resolve(__dirname?? './docs/'?? obj.file + '.md')?? mdStr[obj.group]);
}
obj.callback(err?? res);
});
}
?????????????????????? docs ???????? npm run test:doc ???????? docs ???????????????????е??????????????????????? npm test ????????????package.json???????£?
????"scripts": {
????"test": "export NODE_ENV='test' && mocha"??
????"test:doc": "export NODE_ENV='test' && export GEN_DOC=1 && mocha"
????}
??????????????? API ???????????????? utils ?? test???????????д?????????
?????????????????????????????? test ??????????????? sign: true ???????????? test ??????????????ж???????????????
??????????????????????£?
???????????????????????漰???????????????????SPASVOС??(021-61079698-8054)?????????????????????????
??????
iOS???????mocha??chai??sinon??istanbul???????????????????????????????????????д?????Java????????7??????Android?????????Robolectric3.0????(?)???Kiwi?????????????????????????????????Python?????????????????????????????????????Controller????????д?????????10???????????????????Angular????????????Component??Directive??Pipe ???ServiceAndroid????????????????????????????????--Mockito??????iOS UnitTest???????Vue?????????????????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11????????
?????????App Bug???????????????????????Jmeter?????????QC??????APP????????????????app?????е????????jenkins+testng+ant+webdriver??????????????JMeter????HTTP???????Selenium 2.0 WebDriver ??????