我有一个回调函数,before()用于清理数据库.一切都before()保证在it()开始之前完成吗?
before(function(){
db.collection('user').remove({}, function(res){}); // is it guaranteed to finish before it()?
});
it('test spec', function(done){
// do the test
});
after(function(){
});
Run Code Online (Sandbox Code Playgroud) 鼻子测试框架(用于python)支持在运行时动态生成测试用例(以下,从文档中,导致五个不同的测试用例):
def test_evens():
for i in range(0, 5):
yield check_even, i, i*3
def check_even(n, nn):
assert n % 2 == 0 or nn % 2 == 0
Run Code Online (Sandbox Code Playgroud)
如何使用jocha框架(如mocha或qunit)实现此结果?(此时我不依赖于任何特定的框架.)
我的用例是编写一个测试运行器来监视外部服务器上的几个项目.我会提供一个资源URL列表.每个测试都会尝试轮询该资源,并根据它找到的内容返回成功或失败.我有一个用python构建的原型(使用nose)但是如果可以的话我想在node.js中实现.最终,这将包含在CI设置中.
我有这种情况,我想我想it()在Mocha测试中嵌套测试用例.我确信这是错的,我没有看到任何建议去做我正在做的事情,但我现在还不知道更好的方法 -
基本上,我有一个"父"测试,在父测试中有一个带有所有"子"测试的forEach循环:
it('[test] enrichment', function (done) {
var self = this;
async.each(self.tests, function (json, cb) {
//it('[test] ' + path.basename(json), function (done) {
var jsonDataForEnrichment = require(json);
jsonDataForEnrichment.customer.accountnum = "8497404620452729";
jsonDataForEnrichment.customer.data.accountnum = "8497404620452729";
var options = {
url: self.serverURL + ':' + self.serverPort + '/event',
json: true,
body: jsonDataForEnrichment,
method: 'POST'
};
request(options,function (err, response, body) {
if (err) {
return cb(err);
}
assert.equal(response.statusCode, 201, "Error: Response Code");
cb(null);
});
//});
}, function complete(err) {
done(err)
}); …Run Code Online (Sandbox Code Playgroud)