Table of Contents

Class TestExecutionContext

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

Helper class used to save and restore certain static or singleton settings in the environment that affect tests or which might be changed by the user tests.

public class TestExecutionContext : LongLivedMarshalByRefObject
Inheritance
TestExecutionContext
Derived
Inherited Members

Constructors

TestExecutionContext()

Initializes a new instance of the TestExecutionContext class.

public TestExecutionContext()

TestExecutionContext(TestExecutionContext)

Initializes a new instance of the TestExecutionContext class.

public TestExecutionContext(TestExecutionContext other)

Parameters

other TestExecutionContext

An existing instance of TestExecutionContext.

Properties

CancellationToken

Gets or sets the CancellationToken for the test case.

public CancellationToken CancellationToken { get; }

Property Value

CancellationToken

CurrentContext

Gets and sets the current context.

public static TestExecutionContext CurrentContext { get; }

Property Value

TestExecutionContext

CurrentCulture

Saves or restores the CurrentCulture

public CultureInfo CurrentCulture { get; set; }

Property Value

CultureInfo

CurrentPrincipal

Gets or sets the current IPrincipal for the Thread.

public IPrincipal? CurrentPrincipal { get; set; }

Property Value

IPrincipal

CurrentRepeatCount

The number of times the current test has been scheduled for execution. Currently only being executed in a test using the RetryAttribute

public int CurrentRepeatCount { get; set; }

Property Value

int

CurrentResult

Gets or sets the current test result

public TestResult CurrentResult { get; set; }

Property Value

TestResult

CurrentTest

Gets or sets the current test

public Test CurrentTest { get; set; }

Property Value

Test

CurrentUICulture

Saves or restores the CurrentUICulture

public CultureInfo CurrentUICulture { get; set; }

Property Value

CultureInfo

CurrentValueFormatter

The current head of the ValueFormatter chain, copied from MsgUtils.ValueFormatter

public ValueFormatter CurrentValueFormatter { get; }

Property Value

ValueFormatter

DefaultFloatingPointTolerance

Default tolerance value used for floating point equality when no other tolerance is specified.

public Tolerance DefaultFloatingPointTolerance { get; set; }

Property Value

Tolerance

Dispatcher

The current WorkItemDispatcher. Made public for use by nunitlite.tests

public IWorkItemDispatcher Dispatcher { get; set; }

Property Value

IWorkItemDispatcher

Duration

Gets the elapsed time for running the test in seconds

public double Duration { get; }

Property Value

double

ExecutionStatus

Gets an enum indicating whether a stop has been requested.

public TestExecutionStatus ExecutionStatus { get; set; }

Property Value

TestExecutionStatus

IsSingleThreaded

If true, all tests must run on the same thread. No new thread may be spawned.

public bool IsSingleThreaded { get; set; }

Property Value

bool

OutWriter

Gets a TextWriter that will send output to the current test result.

public TextWriter OutWriter { get; }

Property Value

TextWriter

ParallelScope

The ParallelScope to be used by tests running in this context. For builds with out the parallel feature, it has no effect.

public ParallelScope ParallelScope { get; set; }

Property Value

ParallelScope

RandomGenerator

Gets the RandomGenerator specific to this Test

public Randomizer RandomGenerator { get; }

Property Value

Randomizer

StartTicks

The time the current test started in Ticks

public long StartTicks { get; set; }

Property Value

long

StartTime

The time the current test started execution

public DateTime StartTime { get; set; }

Property Value

DateTime

StopOnError

Get or set indicator that run should stop on the first error

public bool StopOnError { get; set; }

Property Value

bool

TestCaseTimeout

Gets or sets the test case timeout value

public int TestCaseTimeout { get; set; }

Property Value

int

TestObject

The current test object - that is the user fixture object on which tests are being executed.

public object? TestObject { get; set; }

Property Value

object

TestWorker

The worker that spawned the context. For builds without the parallel feature, it is null.

public TestWorker? TestWorker { get; }

Property Value

TestWorker

UpstreamActions

Gets a list of ITestActions set by upstream tests

public List<ITestAction> UpstreamActions { get; }

Property Value

List<ITestAction>

UseCancellation

Gets or sets whether the test case should use a CancellationToken.

public bool UseCancellation { get; set; }

Property Value

bool

Methods

AddFormatter(ValueFormatterFactory)

Adds a new ValueFormatterFactory to the chain of formatters

public void AddFormatter(ValueFormatterFactory formatterFactory)

Parameters

formatterFactory ValueFormatterFactory

The new factory

EstablishExecutionEnvironment()

Set up the execution environment to match a context. Note that we may be running on the same thread where the context was initially created or on a different thread.

public void EstablishExecutionEnvironment()

IncrementAssertCount()

Increments the assert count by one.

public void IncrementAssertCount()

IncrementAssertCount(int)

Increments the assert count by a specified amount.

public void IncrementAssertCount(int count)

Parameters

count int

SendMessage(string, string)

Sends a message from test to listeners. This message is not kind of test output and doesn't go to test result.

public void SendMessage(string destination, string message)

Parameters

destination string

A name recognized by the intended listeners.

message string

A message to be sent

UpdateContextFromEnvironment()

Record any changes in the environment made by the test code in the execution context so it will be passed on to lower level tests.

public void UpdateContextFromEnvironment()