Table of Contents

Class TestAttribute

Namespace
NUnit.Framework
Assembly
nunit.framework.dll

Adding this attribute to a method within a TestFixtureAttribute class makes the method callable from the NUnit test runner. There is a property called Description which is optional which you can provide a more detailed test description. This class cannot be inherited.

[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = true)]
public class TestAttribute : NUnitAttribute, ISimpleTestBuilder, IApplyToTest, IImplyFixture
Inheritance
TestAttribute
Implements
Inherited Members

Examples

[TestFixture] public class Fixture { [Test] public void MethodToTest() {}

[Test(Description = "more detailed description")] public void TestDescriptionMethod() {} }

Constructors

TestAttribute()

public TestAttribute()

Properties

Author

The author of this test

public string Author { get; set; }

Property Value

string

Description

Descriptive text for this test

public string Description { get; set; }

Property Value

string

ExpectedResult

Gets or sets the expected result.

public object ExpectedResult { get; set; }

Property Value

object

The result.

HasExpectedResult

Returns true if an expected result has been set

public bool HasExpectedResult { get; }

Property Value

bool

TestOf

The type that this test is testing

public Type TestOf { get; set; }

Property Value

Type

Methods

ApplyToTest(Test)

Modifies a test by adding a description, if not already set.

public void ApplyToTest(Test test)

Parameters

test Test

The test to modify

BuildFrom(MethodInfo, Test)

Construct a TestMethod from a given MethodInfo.

public TestMethod BuildFrom(MethodInfo method, Test suite)

Parameters

method MethodInfo

The MethodInfo for which a test is to be constructed.

suite Test

The suite to which the test will be added.

Returns

TestMethod

A TestMethod