Is there a way to declare a timeout period using NUnit?

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

I think something like the following should exist, but I cannot find it in the API

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

      

0


a source to share


2 answers


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



+2


a source


AFAIK there's nothing built into NUnit that will do this, but it should be easy enough to do with DateTimes (or performance counters if you want higher resolution timers) ...



+1


a source







All Articles