Table of Contents

Class TestResult

Namespace
NUnit.Framework.Internal
Assembly
nunit.framework.dll

The TestResult class represents the result of a test.

public abstract class TestResult : LongLivedMarshalByRefObject, ITestResult, IXmlNodeBuilder
Inheritance
TestResult
Implements
Derived
Inherited Members

Constructors

TestResult(ITest)

Construct a test result given a Test

public TestResult(ITest test)

Parameters

test ITest

The test to be used

Fields

InternalAssertCount

Aggregate assertion count

protected int InternalAssertCount

Field Value

int

RwLock

ReaderWriterLock

protected ReaderWriterLockSlim RwLock

Field Value

ReaderWriterLockSlim

Properties

AssertCount

Gets or sets the count of asserts executed when running the test.

public int AssertCount { get; }

Property Value

int

AssertionResults

Gets a list of assertion results associated with the test.

public IList<AssertionResult> AssertionResults { get; }

Property Value

IList<AssertionResult>

Children

Gets the collection of child results.

public abstract IEnumerable<ITestResult> Children { get; }

Property Value

IEnumerable<ITestResult>

Duration

Gets or sets the elapsed time for running the test in seconds

public double Duration { get; set; }

Property Value

double

EndTime

Gets or sets the time the test finished running.

public DateTime EndTime { get; set; }

Property Value

DateTime

FailCount

Gets the number of test cases that failed when running the test and all its children.

public abstract int FailCount { get; }

Property Value

int

FullName

Gets the full name of the test result

public virtual string FullName { get; }

Property Value

string

HasChildren

Indicates whether this result has any child results.

public abstract bool HasChildren { get; }

Property Value

bool

InconclusiveCount

Gets the number of test cases that were inconclusive when running the test and all its children.

public abstract int InconclusiveCount { get; }

Property Value

int

Message

Gets the message associated with a test failure or with not running the test

public string Message { get; }

Property Value

string

Name

Gets the name of the test result

public virtual string Name { get; }

Property Value

string

OutWriter

Gets a TextWriter, which will write output to be included in the result.

public TextWriter OutWriter { get; }

Property Value

TextWriter

Output

Gets any text output written to this result.

public string Output { get; }

Property Value

string

PassCount

Gets the number of test cases that passed when running the test and all its children.

public abstract int PassCount { get; }

Property Value

int

PendingFailures

Gets a count of pending failures (from Multiple Assert)

public int PendingFailures { get; }

Property Value

int

ResultState

Gets the ResultState of the test result, which indicates the success or failure of the test.

public ResultState ResultState { get; }

Property Value

ResultState

SkipCount

Gets the number of test cases that were skipped when running the test and all its children.

public abstract int SkipCount { get; }

Property Value

int

StackTrace

Gets any stack trace associated with an error or failure.

public virtual string? StackTrace { get; }

Property Value

string

StartTime

Gets or sets the time the test started running.

public DateTime StartTime { get; set; }

Property Value

DateTime

Test

Gets the test with which this result is associated.

public ITest Test { get; }

Property Value

ITest

TestAttachments

Gets the collection of files attached to the test

public ICollection<TestAttachment> TestAttachments { get; }

Property Value

ICollection<TestAttachment>

TotalCount

Gets the number of test cases executed when running the test and all its children.

public abstract int TotalCount { get; }

Property Value

int

WarningCount

Gets the number of test cases that had warnings when running the test and all its children.

public abstract int WarningCount { get; }

Property Value

int

WorstAssertionStatus

Gets the worst assertion status (highest enum) in all the assertion results

public AssertionStatus WorstAssertionStatus { get; }

Property Value

AssertionStatus

Methods

AddToXml(TNode, bool)

Adds the XML representation of the result as a child of the supplied parent node..

public virtual TNode AddToXml(TNode parentNode, bool recursive)

Parameters

parentNode TNode

The parent node.

recursive bool

If true, descendant results are included

Returns

TNode

RecordAssertion(AssertionResult)

Record an assertion result

public void RecordAssertion(AssertionResult assertion)

Parameters

assertion AssertionResult

RecordAssertion(AssertionStatus, string)

Record an assertion result

public void RecordAssertion(AssertionStatus status, string message)

Parameters

status AssertionStatus
message string

RecordAssertion(AssertionStatus, string, string?)

Record an assertion result

public void RecordAssertion(AssertionStatus status, string message, string? stackTrace)

Parameters

status AssertionStatus
message string
stackTrace string

RecordException(Exception)

Set the test result based on the type of exception thrown

public void RecordException(Exception ex)

Parameters

ex Exception

The exception that was thrown

RecordException(Exception, FailureSite)

Set the test result based on the type of exception thrown

public void RecordException(Exception ex, FailureSite site)

Parameters

ex Exception

The exception that was thrown

site FailureSite

The FailureSite to use in the result

RecordTearDownException(Exception)

RecordTearDownException appends the message and stack trace from an exception arising during teardown of the test to any previously recorded information, so that any earlier failure information is not lost. Note that calling Assert.Ignore, Assert.Inconclusive, etc. during teardown is treated as an error. If the current result represents a suite, it may show a teardown error even though all contained tests passed.

public void RecordTearDownException(Exception ex)

Parameters

ex Exception

The Exception to be recorded

RecordTestCompletion()

Update overall test result, including legacy Message, based on AssertionResults that have been saved to this point.

public void RecordTestCompletion()

SetResult(ResultState)

Set the result of the test

public void SetResult(ResultState resultState)

Parameters

resultState ResultState

The ResultState to use in the result

SetResult(ResultState, string)

Set the result of the test

public void SetResult(ResultState resultState, string message)

Parameters

resultState ResultState

The ResultState to use in the result

message string

A message associated with the result state

SetResult(ResultState, string, string?)

Set the result of the test

public void SetResult(ResultState resultState, string message, string? stackTrace)

Parameters

resultState ResultState

The ResultState to use in the result

message string

A message associated with the result state

stackTrace string

Stack trace giving the location of the command

ToXml(bool)

Returns the XML representation of the result.

public TNode ToXml(bool recursive)

Parameters

recursive bool

If true, descendant results are included

Returns

TNode

An XmlNode representing the result