ccy*_*ccy 9 javascript testing mocha.js node.js
我有一些要求需要多次重试mocha失败测试.有没有简单的方法/解决方法来做到这一点?
我尝试了https://github.com/giggio/mocha-retry,但它对我来说似乎不适用于Mocha 1.21.3:
it (2, 'sample test', function(done) {
expect(1).to.equal(2);
done();
});
Run Code Online (Sandbox Code Playgroud)
mocha test/retry.js -g 'sample test' --ui mocha-retry
Dev*_*yal 10
it (2, 'sample test', function(done) {
this.retries(2); pass the maximum no of retries
expect(1).to.equal(2);
done();
});
Run Code Online (Sandbox Code Playgroud)
// this.retries(最多没有重试次数);
如果您的测试用例失败,则会再次重新执行相同的测试用例,直到达到最大重试次数或测试用例通过为止.一旦您的测试用例通过,它将跳转到下一个测试用例.
有可能要求 mocha 在控制台中重试失败的测试:
mocha test/retry.js -g 'sample test' --retries 2
Run Code Online (Sandbox Code Playgroud)
lag*_*lex -2
try{}catch和递归
var tries_threshold = 5;
it(2, 'sample test', function(done) {
var tries = 0;
function actual_test() {
expect(1).to.equal(2);
}
function test() {
try {
actual_test();
} catch (err) {
if (err && tries++ < tries_threshold)
test();
else done(err);
}
}
test();
});
Run Code Online (Sandbox Code Playgroud)
try{}catch将有助于防止错误冒泡,直到您想要它为止,因此允许您递归地继续尝试。
| 归档时间: |
|
| 查看次数: |
3432 次 |
| 最近记录: |