Instale via npm:
NPM Install Nodeunit -g
Suporta a linha de comando, o navegador é executado. Várias afirmações. Exportar modularmente exportações para o método no node.js. Se você exportar módulo.Exports para objeto, o módulo será a base para o teste de unidade. Veja o seguinte código Node.js:
var fs = requer ('fs'), global = requer ('./ global.js'); var utils = {startwith: function (s1, s) {if (s == null || s == "" "| true;},/ * gerar Guid */getGuid: function () {var guerd = ""; para (var i = 1; i <= 32; i ++) {var n = Math.floor (math.random () * 16.0) .ToString (16);+= n;} return;},/ *). fs.readfilesync (global.logfile, "utf-8"), _ newlog = text? (texto + "/r/n" + log): log; fs.WriteFile (global.logfile, _newlog, function (err) {if (err) tiro err;});}}; exports.utils = utils;./global.js é um arquivo de variável global local. Agora usamos a Nodeunidade para testar o código acima:
var utils = new requer ('./ utils.js'); this.testForutils = {'testGetGuid': function (test) {var guid = utils.utils.getguid (); test.ok (!! guid, 'getguid não deve ser nul. flag = false; utils.utils.WritELog ("Mensagem de teste"); flag = true; test.ok (sinalizador, 'writeLog'); test.done ();}, 'testStartWithwords': function (test) {var = "ad_123"; test.ok (utils.utils.startwith (name ";" ad_123 "; ok "); test.done ();}};test.ok também é a afirmação que geralmente dizemos. Para programas de teste de unidade de nodeunidade, você também pode usar o inspetor de nó para depurar