Reputation: 760
Hi i would like to log the test failed message , I know its possible to check the status in
TearDown
Using the following
TestContext.CurrentContext.Result.Status.ToString();
Is possible to get the reason for test fail in TearDown . Some thing like the following
Expected: True
But was: False
at NUnit.Framework.Assert.That(Object actual, IResolveConstraint expression, String message, Object[] args)
at NUnit.Framework.Assert.IsTrue(Boolean condition)
at Test.FileSystemTests.QuoteFiles() in ExampleTests.cs: line 57
Upvotes: 7
Views: 5874
Reputation: 809
If
TestContext.CurrentContext.Result
does not contain the values you are looking for, you can also try
TestExecutionContext.CurrentContext.CurrentResult
This worked for me with NUnit 3.0 in the TearDown as well as other methods.
Upvotes: 5
Reputation: 11
Hi am not sure you got the solution for this issue. But here is my answer for this. Using Nunit 3.0 you can achieve this with below lines...
TestContext.CurrentContext.Result.Outcome.Status; (For test Execution Status)
TestContext.CurrentContext.Result.StackTrace; (For Stack Trace Message)
TestContext.CurrentContext.Result.Message; (For Test Result Message)
Upvotes: 1
Reputation: 6123
This question: NUnit: Accessing the Failure Message in TearDown() could potentially help you. It seems similar enough in intent.
Upvotes: 0
Reputation: 27944
The need for a status in your teardown is an indication of a testsmell. The teardown should work any time without depending on the result of the unit test. I just brings your system in the same state as before your unit test. You can add tries and finally to your teardown to clean the mess. However depending on one assert (and later on more) will make your teardown code complex and that is something your do now want in an unit test.
Upvotes: 0