./global.js是一个本地全局变量文件,现在我们对以上代码使用NodeUnit做测试的node.js代码: var utils=new require('./utils.js'); this.TestForUtils = { 'TestgetGuid': function (test) { var guid=utils.utils.getGuid(); test.ok(!!guid, 'getGuid should not be null.'); test.done(); }, 'TestWritelog': function (test) { var flag=false; utils.utils.writeLog("test message"); flag=true; test.ok(flag,'writeLog'); test.done(); }, 'TestStartWithWords': function (test) { var name="ad_123"; test.ok(utils.utils.startWith(name, "ad_"),"startwith method should be ok"); test.done(); } }; |
test.ok也是通常我们说的断言。对于NodeUnit的单元测试程序,也可以使用node-inspector来调试。