【发布时间】:2012-01-11 19:48:09
【问题描述】:
我正在着手设置 Expresso 并运行一些测试。我跟着tutorial on node tuts 运行并通过了 4 个测试。现在,我试图在运行测试时显示代码覆盖率输出,例如 docs 显示。但是,我有点迷路了。
我的超级基础学习示例测试在名为 test.js 的文件中,位于名为 test 的文件夹中:
var Account = require('../lib/account');
require('should');
module.exports = {
"initial balance should be 0" : function(){
var account = Account.create();
account.should.have.property('balance');
account.balance.should.be.eql(0);
},
"crediting account should increase the balance" : function(){
var account = Account.create();
account.credit(10);
account.balance.should.be.eql(10);
},
"debiting account should decrease the balance" : function(){
var account = Account.create();
account.debit(5);
account.balance.should.be.eql(-5);
},
"transferring from account a to b b should decrease from a and increase b": function(){
var accountA = Account.create();
var accountB = Account.create();
accountA.credit(100);
accountA.transfer(accountB, 25);
accountA.balance.should.be.eql(75);
accountB.balance.should.be.eql(25);
}
}
并且代码本身在 lib/account.js 中:
var Account = function(){
this.balance = 0;
}
module.exports.create = function(){
return new Account();
}
Account.prototype.credit = function(amt){
this.balance += amt;
}
Account.prototype.debit = function(amt){
this.balance -= amt;
}
Account.prototype.transfer = function(acct, amt){
this.debit(amt);
acct.credit(amt);
}
Account.prototype.empty = function(acct){
this.debit(this.balance);
}
当我从命令行运行 expresso 时,我得到:
$ expresso
100% 4 tests
同样,如果我使用-c 标志或各种其他选项运行expresso,我会得到相同的输出。我想获得文档中显示的代码覆盖率输出。我也运行了命令$ node-jscoverage lib lib-cov,现在lib-cov文件夹里有东西了..
我错过了什么?
【问题讨论】:
-
不是只有在你的测试失败时才会有不同的输出吗?
-
是的,但是不管测试是否通过,都应该有额外的代码覆盖输出。图片示例:dl.dropbox.com/u/6396913/cov.png
标签: node.js tdd code-coverage expresso