Search code examples
.netnunit

Is there a way to declare timeout period with NUnit?


I would like to be able to fail the test if the executing code hangs. Is there a way to do this currently?

I am thinking something like the following must exist, but I can't seem to find it in the API

[Test, Timeout(TimeSpan.FromSeconds(2))]
public void Test() { ...}

Solution

  • Are you using NUnit 2.5? A TimeoutAttribute was added in NUnit 2.5 that does exactly what you want, though you specify the timeout in milliseconds. See the release notes.