We encountered a problem when starting automatic tests written in C #. We use NUnit and for Retry in the documentation ( https://github.com/nunit/docs/wiki/Retry-Attribute) I found that 'If a test has an unexpected exception, it is not retained. Only assertion failures can trigger a retry.' The problem is that we have issues in other places - no Asserts (for example unexpected exceptions) because of timeouts, restarts or changes on a test machine during building tests.
We Use NUnit 3.11 On our build, 1 of 300 tests failed because of unexpected exceptions, and the build is failed. If the test would be repeated (for every exception) we can avoid this issue.
[Test, Sequential] [Retry(MaxRetryCount)] .....
Actual: Tests are repeated only after assertion fail, but the issue is that we want to rerun them (e.g. MaxRetryCount=4) after finding every exception.
Expected: Rerun test after every exception.
Although you didn't actually ask a question, I'm assuming that it's something like "Given that NUnit doesn't work the way I thought it did, what can I do about it?"
The usual answer is that you should take the call (or calls) that lead to an error and wrap it (them) in an assertion.
For example, assume that your test calls
DoSomethingThatMayNotWork();
which somewhere deep down throws an exception and terminates the run. You know that this happens intermittently but you would prefer to retry it and have placed the RetryAttribute
on our test method.
In that case, replace the above with something like
Assert.That(() => DoSomethingThatMayNotWork(), Throws.Nothing);
That will convert any unhandled exception into a failure and the test will be retried.
You can refine this by checking for specific exceptions that you expect so that the test is not retried on something like an NRE, which would usually be a programming error.