Reputation: 985
I am trying to find the value that my .Net code uses to alert Visual Studios that a test has failed, passed, or been ignored. I want to be able to use this to determine if a test has passed or failed for basic tracking in our database.
However, short of putting a variable at the end of each test and setting it to "pass", I have no idea how to differentiate between a failed or passed test when running my tear down code.
Thanks for any help!
Upvotes: 1
Views: 3728
Reputation: 23747
You can use the TestContext
:
// Use the necessary namespace
using NUnit.Framework;
...
[TearDown]
public void TearDown()
{
if (TestContext.CurrentContext.Result.Status == TestStatus.Failed)
{
// Your test failed, handle it
}
}
See the documentation here.
Upvotes: 2