Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NUnit - Repeat test case for 3 times, If it fails

I have few test cases for Web Site UI Automation.

I want to try my test case at least three times, if it fails for first and second time. That way, I want to make sure that this test case is failing consistently.

Please let me know, if we have any option to use in NUnit. I am using C# with NUnit.

like image 939
kumar Avatar asked Aug 09 '11 19:08

kumar


People also ask

How do you rerun failed test cases in NUnit?

For every failed test, write the test case name including the containing class name and the namespace to a file. Using nunit-console.exe, rerun the whole spec dll but filtered by that text file, so NUnit will run only the failed tests.

How do you run the same test case multiple times in NUnit?

RepeatAttribute is used on a test method to specify that it should be executed multiple times. If any repetition fails, the remaining ones are not run and a failure is reported.

Which is better NUnit or MsTest?

The main difference is the ability of MsTest to execute in parallel at the method level. Also, the tight integration of MsTest with Visual Studio provides advantages in both speed and robustness when compared to NUnit. As a result, I recommend MsTest.


2 Answers

You can add a new attribute in the nunit based on the attribute repeat and rebuild the library. It's very simple.

   [Test]
   [Repeat( 25 )]
   public void MyTest( ){
      // your test logic here
   }
like image 70
Stanislav Volkov Avatar answered Sep 19 '22 16:09

Stanislav Volkov


Starting with NUnit 3.0, there is a 'Retry' attribute that looks like it will do exactly what kumar wants.

See Retry Attribute

   [Test]
   [Retry(3)]
   public void MyTest( ){
      // your test logic here
   }
like image 44
Brad Oestreicher Avatar answered Sep 20 '22 16:09

Brad Oestreicher