TestContext (NUnit 2.5.7 / 2.6)

Each NUnit test runs in an execution context, which includes information about the environment as well as the test itself. The TestContext class allows tests to access certain information about the execution context.

This class has been present in NUnit since 2.5.7, but was undocumented until the 2.6 release. Those earlier versions of TestContext are not covered here.

CurrentContext

The context of the currently executing test may be accessed by use of the static property CurrentContext, which gets a reference to the current TestContext. This context is created separately for each test before it begins execution.

All other properties apply to the TestContext instance returned by CurrentContext. Note that the context may not be changed - all properties are read-only.

Test

Gets a representation of the current test, with the following properties:

Result

Gets a representation of the test result, with the following properties:

Notes:

  1. The result of the test may be accessed during setup or test execution, but it only has a useful value at in the TearDown method.
  2. The Status value should be used in preference to State wherever possible, since the latter will not be available in future releases.

TestDirectory

Gets the full path of the directory containing the current test assembly.

WorkDirectory

Gets the full path of the directory to be used for output from this test run. The XML result file and any redirected output files are located under this directory. This is normally the directory that was current when execution of NUnit began but may be changed by use of the /work option of nunit-console.