I have some requirement that demands to retry mocha failure tests multiple times. Is there any easy way/workaround to do this?
I tried https://github.com/giggio/mocha-retry, but it doesn't seem to work for me with Mocha 1.21.3:
it (2, 'sample test', function(done) {
expect(1).to.equal(2);
done();
});
mocha test/retry.js -g 'sample test' --ui mocha-retry
To rerun a certain test block you can just apply the number of reruns as last parameter after the test block function: Mocha. Jasmine.
Use Mocha's skip() function. It can be used to either statically to disable a test or entire suite, or dynamically skip it at runtime.
Mocha is a feature-rich JavaScript test framework running on Node.js and in the browser, making asynchronous testing simple and fun. Mocha tests run serially, allowing for flexible and accurate reporting, while mapping uncaught exceptions to the correct test cases. Hosted on GitHub.
There is possibility to ask mocha to retry failed tests in the console:
mocha test/retry.js -g 'sample test' --retries 2
it(2, 'sample test', function(done) {
this.retries(2); // pass the maximum no of retries
expect(1).to.equal(2);
done();
});
If your test case fail than it will re-execute the same test case again until the max no of retries reached or test case get passed. Once your test case get passed it will jump to the next test case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With