Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

retry failed mocha test

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

like image 272
ccy Avatar asked Oct 16 '14 21:10

ccy


People also ask

How do you rerun failed test cases in Wdio?

To rerun a certain test block you can just apply the number of reruns as last parameter after the test block function: Mocha. Jasmine.

How do you skip the Mocha test?

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.

What is Mocha test?

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.


2 Answers

There is possibility to ask mocha to retry failed tests in the console:

mocha test/retry.js -g 'sample test' --retries 2
like image 83
gawi Avatar answered Sep 18 '22 12:09

gawi


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.

like image 31
Devdutta Goyal Avatar answered Sep 19 '22 12:09

Devdutta Goyal