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 : 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

CHILD_ERRORS_MESSAGE

Error message for when child tests have errors

public static readonly string CHILD_ERRORS_MESSAGE

Field Value

string

CHILD_IGNORE_MESSAGE

Error message for when child tests are ignored

public static readonly string CHILD_IGNORE_MESSAGE

Field Value

string

Properties

AssertCount

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

public int AssertCount { get; set; }

Property Value

int

Children

Gets the collection of child results.

public IList<ITestResult> Children { get; }

Property Value

IList<ITestResult>

Duration

Gets or sets the elapsed time for running the test

public TimeSpan Duration { get; set; }

Property Value

TimeSpan

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. Test HasChildren before accessing Children to avoid the creation of an empty collection.

public 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 StringWriter OutWriter { get; }

Property Value

StringWriter

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

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 stacktrace 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

Methods

AddResult(ITestResult)

Adds a child result to this result, setting this result's ResultState to Failure if the child result failed.

public virtual void AddResult(ITestResult result)

Parameters

result ITestResult

The result to be added

AddToXml(XmlNode, bool)

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

public virtual XmlNode AddToXml(XmlNode parentNode, bool recursive)

Parameters

parentNode XmlNode

The parent node.

recursive bool

If true, descendant results are included

Returns

XmlNode

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 stacktrace 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

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 XmlNode ToXml(bool recursive)

Parameters

recursive bool

If true, descendant results are included

Returns

XmlNode

An XmlNode representing the result