Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Timeout for individual tests in NUnit

Tags:

I'm aware that there is a Timeout attribute in NUnit. My problem is that the unit tests actually spawn a new process which, if frozen, is never killed by NUnit. How can I implement a timeout which will actually get rid of the rogue process?

like image 302
Radoslav Hristov Avatar asked Jan 05 '11 15:01

Radoslav Hristov


People also ask

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

You can add a new attribute in the nunit based on the attribute repeat and rebuild the library. It's very simple. Show activity on this post. Starting with NUnit 3.0, there is a 'Retry' attribute that looks like it will do exactly what kumar wants.

Does SetUp run before every test NUnit?

Inheritance. The SetUp attribute is inherited from any base class. Therefore, if a base class has defined a SetUp method, that method will be called before each test method in the derived class.

How do you write multiple test cases in NUnit?

If you add a second parameter with the Values attribute, for per value of the first parameter, NUnit will add a test for every value of the second parameter. Another way to avoid having to write duplicate tests when testing the same behaviour with different inputs is to use TestCase attribute on the test itself.

How does NUnit decide what order to run tests in?

There is no facility in NUnit to order tests globally. Tests with an OrderAttribute argument are started before any tests without the attribute. Ordered tests are started in ascending order of the order argument. Among tests with the same order value or without the attribute, execution order is indeterminate.


1 Answers

You can use timeout for assertion, instead of timeout for whole test method:

Assert.That(actual, Is.EqualTo(expected).After(5000, 50));
like image 111
Sergey Berezovskiy Avatar answered Sep 20 '22 16:09

Sergey Berezovskiy