Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable timeout for unit tests in C#

I'm running into an issue where my tests timeout after 30 minutes. Any ideas on setting infinite timeout? I've tried Timeout(0), but it still throws a timeout after 30 minutes.

I'm running these unit tests in Visual Studio 2008.

like image 395
Eric Avatar asked Mar 25 '11 21:03

Eric


2 Answers

It worked for me. You have to add it to the C# test code, just above the test method:

[Timeout(TestTimeout.Infinite)]
[TestMethod()]
like image 124
Sam Bendayan Avatar answered Sep 30 '22 17:09

Sam Bendayan


Since 30 minutes is the default timeout for a unit test in the Visual Studio test framework, I'm going to take a guess that this is what you're referring to. If not, please provide more details.

You can set this timeout in at least two ways:

  1. Decorate specific TestMethods with an attribute: [Timeout(TestTimeout.Infinite)]; or
  2. Using Test -> Edit Test Settings -> [settings you're using] -> Test Timeouts.

Note that if you do this using (2), you will have to close and re-open your solution in VS before the change is applied.

like image 32
telewin Avatar answered Sep 30 '22 17:09

telewin