富贵资源网 Design By www.hznty.com

通过NPM安装:

  npm install nodeunit -g

  支持命令行,浏览器运行. 各种断言。 在node.js下模块化对于方法导出exports, 如果是对象导出module.exports,模块儿是单元测试的基础,看下面的node.js代码:

var fs = require('fs'),
global=require('./global.js');
var utils = {
startWith: function(s1, s) {
if (s == null || s == "" || this.length == 0 || s.length > this.length)
return false;
if (s1.substr(0, s.length) == s)
return true;
else
return false;
return true;
},
/* Generate GUID */
getGuid: function() {
var guid = "";
for (var i = 1; i <= 32; i++) {
var n = Math.floor(Math.random() * 16.0).toString(16);
guid += n;
}
return guid;
},
/* add log information */
writeLog: function(log) {
if(!log) return;
var text = fs.readFileSync(global.logFile, "utf-8"),
_newLog = text "\r\n" + log) : log;
fs.writeFile(global.logFile, _newLog, function(err){
if(err) throw err;
});
}
};
exports.utils=utils;

./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来调试

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。