Title: mocha - Retry Whole Test
Tags: javascript;testing;mocha.js;appium;webdriver-io
Question: Is there a way to retry an entire test case if any test suite within it fails? 

I have tried using ```this.retries()``` but for some reason whenever my test fails, it just stops after one run. Using it in a specific test suite works but it gives me false positives (test passes even though it's on the wrong screen) plus this won't work if my test fails on the before hook. I've also tried using the ```retries``` option but it also stopped after one failed run.

I'm using ```Appium``` with ```MochaJS``` and ```WebdriverIO``` to test an Android app.

EDIT: Not using TestNG or any other frameworks other than those listed above.



Here is another answer: You can use Retry Analyzer, just create a method:

```public class RetryAnalyzer implements IRetryAnalyzer {
    int counter = 1;
    int retryLimit = 3; //Change the limit, how many time you want to retry

    @Override
    public boolean retry(ITestResult result) {
        if(counter < retryLimit) {
            counter++;
            return true;
        }
        return false;
    }
}
```

Use above method in ```@Test``` annotation like below:

```@Test(retryAnalyzer = RetryAnalyzer.class)
    public void testCaseName() throws Exception {
        //Your code
    }
```

Comment for this answer: Yeah, you have to use TestNG framework for this feature.
Comment for this answer: This is in C# and TestNG right? Would this be similar in Javascript and without testNG?
Comment for this answer: I see my mistake so its not possible without TestNG right? Do you have any suggestions for Mocha/WebdriverIO?
Comment for this answer: Are there any alternatives for non TestNG testers?

Here is another answer: Ideally this.retries option in mocha should work just fine in Webdriverio unless you are using fat arrow functions in your test suites/test cases. Please try to reach out Webdriverio gitter channel for latest issues or for work around. They are extremely helpful.


{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 4.0', 'CreationDate': '2018:00:07/19/18', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<javascript><testing><mocha.js><appium><webdriver-io>', 'Title': 'mocha - Retry Whole Test', 'ViewCount': 863, 'id': 51413676, 'user_AboutMe': '<p>Looking for unpaid internships to learn about game development</p>\n', 'user_AccountId': 13757442.0, 'user_DisplayName': 'Reina Reinhart', 'user_Reputation': 75.0, 'user_Views': 19.0, 'user_id': 9927977.0}}