<PackageReference Include="NUnit" Version="4.3.1" />

TestExecutionContext

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.

An AdhocTestExecutionContext is created whenever a context is needed but not available in CurrentContext. This happens when tests are run on an ad-hoc basis or Asserts are used outside of tests.

An IsolatedContext is used when running code that may effect the current result in ways that should not impact the final result of the test. A new TestExecutionContext is created with an initially clear result, which is discarded on exiting the context.

public static TestExecutionContext CurrentContext { get; }

Gets and sets the current context.

Gets or sets the CancellationToken for the test case.

public CultureInfo CurrentCulture { get; set; }

Saves or restores the CurrentCulture

public IPrincipal CurrentPrincipal { get; set; }

Gets or sets the current IPrincipal for the Thread.

public int CurrentRepeatCount { get; set; }

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

public TestResult CurrentResult { get; set; }

Gets or sets the current test result

public Test CurrentTest { get; set; }

Gets or sets the current test

public CultureInfo CurrentUICulture { get; set; }

Saves or restores the CurrentUICulture

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

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

public IWorkItemDispatcher Dispatcher { get; set; }

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

public double Duration { get; }

Gets the elapsed time for running the test in seconds

public TestExecutionStatus ExecutionStatus { get; set; }

Gets an enum indicating whether a stop has been requested.

public bool IsSingleThreaded { get; set; }

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

public TextWriter OutWriter { get; }

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

public ParallelScope ParallelScope { get; set; }

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

public Randomizer RandomGenerator { get; }

Gets the RandomGenerator specific to this Test

public long StartTicks { get; set; }

The time the current test started in Ticks

public DateTime StartTime { get; set; }

The time the current test started execution

public bool StopOnError { get; set; }

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

public int TestCaseTimeout { get; set; }

Gets or sets the test case timeout value

public object TestObject { get; set; }

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

public TestWorker TestWorker { get; }

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

public List<ITestAction> UpstreamActions { get; }

Gets a list of ITestActions set by upstream tests

public bool UseCancellation { get; set; }

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

Initializes a new instance of the TestExecutionContext class.

Initializes a new instance of the TestExecutionContext class.

public void AddFormatter(ValueFormatterFactory formatterFactory)

Adds a new ValueFormatterFactory to the chain of formatters

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 IncrementAssertCount()

Increments the assert count by one.

public void IncrementAssertCount(int count)

Increments the assert count by a specified amount.

public void SendMessage(string destination, string message)

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

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.