Table of Contents

Class Test

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

The Test abstract class represents a test within the framework.

public abstract class Test : ITest, IXmlNodeBuilder, IComparable, IComparable<Test>
Inheritance
Test
Implements
Derived
Inherited Members

Constructors

Test(IMethodInfo)

Constructs a test for a specific method.

protected Test(IMethodInfo method)

Parameters

method IMethodInfo

Test(ITypeInfo)

Constructs a test for a specific type.

protected Test(ITypeInfo typeInfo)

Parameters

typeInfo ITypeInfo

Test(string)

Constructs a test given its name

protected Test(string name)

Parameters

name string

The name of the test

Test(string?, string)

Constructs a test given the path through the test hierarchy to its parent and a name.

protected Test(string? pathName, string name)

Parameters

pathName string

The parent tests full name

name string

The name of the test

Properties

Arguments

The arguments to use in creating the test or empty array if none required.

public abstract object?[] Arguments { get; }

Property Value

object[]

ClassName

Gets the name of the class where this test was declared. Returns null if the test is not associated with a class.

public string? ClassName { get; }

Property Value

string

Fixture

Gets or sets a fixture object for running this test.

public virtual object? Fixture { get; set; }

Property Value

object

FullName

Gets or sets the fully qualified name of the test

public string FullName { get; set; }

Property Value

string

HasChildren

Gets a bool indicating whether the current test has any descendant tests.

public abstract bool HasChildren { get; }

Property Value

bool

Id

Gets or sets the id of the test

public string Id { get; set; }

Property Value

string

IdPrefix

Static prefix used for ids in this AppDomain. Set by FrameworkController.

public static string? IdPrefix { get; set; }

Property Value

string

IsSuite

Returns true if this is a TestSuite

public bool IsSuite { get; }

Property Value

bool

Method

Gets a MethodInfo for the method implementing this test. Returns null if the test is not implemented as a method.

public IMethodInfo? Method { get; set; }

Property Value

IMethodInfo

MethodName

Gets the name of the method implementing this test. Returns null if the test is not implemented as a method.

public virtual string? MethodName { get; }

Property Value

string

Name

Gets or sets the name of the test

public string Name { get; set; }

Property Value

string

Parent

Gets the parent as a Test object. Used by the core to set the parent.

public ITest? Parent { get; set; }

Property Value

ITest

Properties

Gets the properties for this test

public IPropertyBag Properties { get; }

Property Value

IPropertyBag

RunState

Whether or not the test should be run

public RunState RunState { get; set; }

Property Value

RunState

Seed

Gets or Sets the Int value representing the seed for the RandomGenerator

public int Seed { get; set; }

Property Value

int

SetUpMethods

The SetUp methods.

public IMethodInfo[] SetUpMethods { get; protected set; }

Property Value

IMethodInfo[]

TearDownMethods

The teardown methods

public IMethodInfo[] TearDownMethods { get; protected set; }

Property Value

IMethodInfo[]

TestCaseCount

Gets a count of test cases represented by or contained under this test.

public virtual int TestCaseCount { get; }

Property Value

int

TestType

Gets a string representing the type of test. Used as an attribute value in the XML representation of a test and has no other function in the framework.

public virtual string TestType { get; }

Property Value

string

Tests

Gets this test's child tests

public abstract IList<ITest> Tests { get; }

Property Value

IList<ITest>

A list of child tests

TypeInfo

Gets the TypeInfo of the fixture used in running this test or null if no fixture type is associated with it.

public ITypeInfo? TypeInfo { get; }

Property Value

ITypeInfo

XmlElementName

Gets the name used for the top-level element in the XML representation of this test

public abstract string XmlElementName { get; }

Property Value

string

Methods

AddToXml(TNode, bool)

Returns an XmlNode representing the current result after adding it as a child of the supplied parent node.

public abstract TNode AddToXml(TNode parentNode, bool recursive)

Parameters

parentNode TNode

The parent node.

recursive bool

If true, descendant results are included

Returns

TNode

ApplyAttributesToTest(ICustomAttributeProvider)

Modify a newly constructed test by applying any of NUnit's common attributes, based on a supplied ICustomAttributeProvider, which is usually the reflection element from which the test was constructed, but may not be in some instances. The attributes retrieved are saved for use in subsequent operations.

public void ApplyAttributesToTest(ICustomAttributeProvider provider)

Parameters

provider ICustomAttributeProvider

ApplyAttributesToTest(Type)

Recursively apply the attributes on type to this test, including attributes on nesting types.

public void ApplyAttributesToTest(Type type)

Parameters

type Type

The

CompareTo(Test?)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

public int CompareTo(Test? other)

Parameters

other Test

An object to compare with this instance.

Returns

int

CompareTo(object?)

Compares the current instance with another object of the same type and returns an integer that indicates whether the current instance precedes, follows, or occurs in the same position in the sort order as the other object.

public int CompareTo(object? obj)

Parameters

obj object

An object to compare with this instance.

Returns

int

GetCustomAttributes<TAttr>(bool)

Get custom attributes applied to a test

public virtual TAttr[] GetCustomAttributes<TAttr>(bool inherit) where TAttr : class

Parameters

inherit bool

Returns

TAttr[]

Type Parameters

TAttr

GetNestedTypes(Type)

Returns all nested types, inner first.

protected IEnumerable<Type> GetNestedTypes(Type inner)

Parameters

inner Type

Returns

IEnumerable<Type>

MakeInvalid(Exception, string)

Mark the test as Invalid (not runnable) specifying a reason and an exception.

public void MakeInvalid(Exception exception, string reason)

Parameters

exception Exception

The exception that was the cause.

reason string

The reason the test is not runnable

MakeInvalid(string)

Mark the test as Invalid (not runnable) specifying a reason

public void MakeInvalid(string reason)

Parameters

reason string

The reason the test is not runnable

MakeTestResult()

Creates a TestResult for this test.

public abstract TestResult MakeTestResult()

Returns

TestResult

A TestResult suitable for this type of test.

PopulateTestNode(TNode, bool)

Add standard attributes and members to a test node.

protected void PopulateTestNode(TNode thisNode, bool recursive)

Parameters

thisNode TNode
recursive bool

ToXml(bool)

Returns the XML representation of the test

public TNode ToXml(bool recursive)

Parameters

recursive bool

If true, include child tests recursively

Returns

TNode