Reputation: 3
I am migrating our Project from MSTest to NUnit. I have a scenario where I need to execute the below condition
testContext.CurrentTestOutcome.Equals(UnitTestOutcome.Timeout)
Can you please suggest the NUnit equivalent to MSTest's UnitTestOutcome.Timeout
?
Upvotes: 0
Views: 258
Reputation: 13681
The question is not entirely clear. @Francesco B. already interpreted it as meaning "How can I specify a timeout?" and answered accordingly.
I understand you to be asking "How can I detect that my test has timed out?" Short answer - you can't detect it in the test itself. It can only be detected by a runner that is executing your test.
Longer answer...
You can examine the test context in your teardown to see what was the outcome of the test using TestContext.CurrentContext.Result.Outcome
. This is useful if your teardown needs to know the test has failed.
However, you will never see an outcome of "timed out" because...
Of course, if I misunderstood the question and you just wanted to know how to specify a timeout, the other answer is what you want. :-)
Upvotes: 1
Reputation: 3097
As per the official documentation, you can use the Timeout
attribute:
[Test, Timeout(2000)]
public void PotentiallyLongRunningTest()
{
...
}
Of course you will have to provide the timeout value in milliseconds; past that limit, your test will be listed as failed.
There is a known "rare" case where NUnit doesn't respect the timeout, which has already been discussed.
Upvotes: 0