Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get test fail message in NUnit TearDown

Tags:

c#

nunit

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
like image 881
Anand S Avatar asked Oct 04 '22 22:10

Anand S


2 Answers

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.

like image 145
Erick Stone Avatar answered Oct 10 '22 02:10

Erick Stone


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)
like image 42
Prabu Ramaraj Avatar answered Oct 10 '22 01:10

Prabu Ramaraj