Commit 8349d21005edc5f24a79ffab5fa66d4e8b7c12e0

Authored by sumatek
1 parent c84b1639
Exists in master

update unittest

app.js
... ... @@ -74,6 +74,9 @@ app.use(function (req, res, next) {
74 74  
75 75 // console.log(conf.get('redis.host'));
76 76  
  77 +
  78 +utils.test(1,2);
  79 +
77 80 // setup generate request-id middleware
78 81 const addRequestId = require('express-request-id')();
79 82 app.use(addRequestId);
... ...
unitTest/readme.txt 0 → 100644
... ... @@ -0,0 +1,19 @@
  1 +//npm
  2 +npm install fs
  3 +npm install path
  4 +npm install read-text-file
  5 +
  6 +//how to use
  7 +var unit = require('./unitTest/unitTest');
  8 +var test = function(a,b){
  9 + var returnData = a+b;
  10 + unit(arguments,returnData,'test');
  11 + return returnData;
  12 +}
  13 +
  14 +//concept
  15 +1.get data in function to testCase.txt
  16 +2.mocha read testCase.txt
  17 +
  18 +//env
  19 +gentest
0 20 \ No newline at end of file
... ...
unitTest/test.js
... ... @@ -15,16 +15,19 @@ try{
15 15 describe('unitTest app',function() {
16 16  
17 17 for(var i=0;i<testCase.length;i++)
18   - {
19   - var func = require(dir.dir+path.sep+testCase[i].from);
  18 + {
  19 +
  20 + var func = require(dir.dir+path.sep+testCase[i].from);
20 21 var expect = testCase[i].expect;
21 22 var comment = testCase[i].comment!=""?" => "+testCase[i].comment:testCase[i].comment;
22 23  
23   -
24   -
25 24 testCase[i].input = getTrueData(testCase[i].input);
26 25  
27   - var cal = func[testCase[i].function](...testCase[i].input);
  26 + var cal = '';
  27 + if(func[testCase[i].function])
  28 + cal = func[testCase[i].function](...testCase[i].input);
  29 +
  30 +
28 31 it(testCase[i].function+comment ,function(done) {
29 32  
30 33 if (expect == cal) {
... ...
unitTest/testCase.txt
... ... @@ -2,3 +2,5 @@
2 2 {"function":"findCmdfromMethod","input":["GET"],"expect":"QUERY","from":"utils\\utils.js","comment":"GET"}
3 3 {"function":"findCmdfromMethod","input":["GET"],"expect":"QUERY","from":"utils\\utils.js","comment":"GET"}
4 4 {"function":"findCmdfromMethod","input":["GET"],"expect":"QUERY","from":"utils\\utils.js","comment":"GET"}
  5 +{"function":"test","input":[1,2],"expect":3,"from":"utils\\utils.js","comment":"test"}
  6 +{"function":"test","input":[1,2],"expect":3,"from":"utils\\utils.js","comment":"test"}
... ...
unitTest/unitTest.js
... ... @@ -73,13 +73,13 @@ function getFunName(level)
73 73 return track[track.length-1];
74 74 }
75 75  
76   -if(process.env.NODE_ENV == env)
77   -{
78   - try {
79   - fs.unlinkSync(fileTempUnitTest);
80   - } catch (error) {
  76 +// if(process.env.NODE_ENV == env)
  77 +// {
  78 +// try {
  79 +// fs.unlinkSync(fileTempUnitTest);
  80 +// } catch (error) {
81 81  
82   - }
83   -}
  82 +// }
  83 +// }
84 84  
85 85  
... ...
utils/utils.js
... ... @@ -128,6 +128,13 @@ utils.testUnit = function(testObj,testInt,testArray,testObj2)
128 128 return returnData;
129 129 }
130 130  
  131 +
  132 +utils.test = function(a,b){
  133 + var returnData = a+b;
  134 + unitTest(arguments,returnData,'test');
  135 + return returnData;
  136 + }
  137 +
131 138 function findValueInBracket(data)
132 139 {
133 140 data = data.substring(1,data.length-1);
... ... @@ -245,4 +252,7 @@ getQuery = async function(data,query){
245 252  
246 253  
247 254  
248   -module.exports = utils;
249 255 \ No newline at end of file
  256 +module.exports = utils;
  257 +
  258 +
  259 +
... ...