Class TestContext
Provide the context information of the current test. This is an adapter for the internal ExecutionContext class, hiding the internals from the user test.
public class TestContext
- Inheritance
-
TestContext
- Inherited Members
Constructors
TestContext(TestExecutionContext)
Construct a TestContext for an ExecutionContext
public TestContext(TestExecutionContext testExecutionContext)
Parameters
testExecutionContext
TestExecutionContextThe ExecutionContext to adapt
Fields
Error
Gets a TextWriter that will send output directly to Console.Error
public static TextWriter Error
Field Value
Parameters
TestParameters object holds parameters for the test run, if any are specified
public static readonly TestParameters Parameters
Field Value
Progress
Gets a TextWriter for use in displaying immediate progress messages
public static readonly TextWriter Progress
Field Value
Properties
AssertCount
Gets the number of assertions executed up to this point in the test.
public int AssertCount { get; }
Property Value
CancellationToken
Gets the CancellationToken for the test case.
public CancellationToken CancellationToken { get; }
Property Value
CurrentContext
Get the current test context. This is created as needed. The user may save the context for use within a test, but it should not be used outside the test for which it is created.
public static TestContext CurrentContext { get; }
Property Value
CurrentRepeatCount
Get the number of times the current Test has been repeated when using the RetryAttribute or RepeatAttribute.
public int CurrentRepeatCount { get; }
Property Value
Out
Gets a TextWriter that will send output to the current test result.
public static TextWriter Out { get; }
Property Value
Random
Gets the random generator.
public Randomizer Random { get; }
Property Value
- Randomizer
The random generator.
Result
Gets a Representation of the TestResult for the current test.
public TestContext.ResultAdapter Result { get; }
Property Value
Test
Get a representation of the current test.
public TestContext.TestAdapter Test { get; }
Property Value
TestDirectory
Gets the directory containing the current test assembly.
public string TestDirectory { get; }
Property Value
WorkDirectory
Gets the directory to be used for outputting files created by this test run.
public string WorkDirectory { get; }
Property Value
WorkerId
Gets the unique name of the Worker that is executing this test.
public string? WorkerId { get; }
Property Value
Methods
AddFormatter(ValueFormatterFactory)
This method adds the a new ValueFormatterFactory to the chain of responsibility used for formatting values in messages. The scope of the change is the current TestContext.
public static void AddFormatter(ValueFormatterFactory formatterFactory)
Parameters
formatterFactory
ValueFormatterFactoryThe factory delegate
AddFormatter<TSupported>(ValueFormatter)
This method provides a simplified way to add a ValueFormatter delegate to the chain of responsibility, creating the factory delegate internally. It is useful when the Type of the object is the only criterion for selection of the formatter, since it can be used without getting involved with a compound function.
public static void AddFormatter<TSupported>(ValueFormatter formatter)
Parameters
formatter
ValueFormatterThe ValueFormatter delegate
Type Parameters
TSupported
The type supported by this formatter
AddTestAttachment(string, string?)
Attach a file to the current test result
public static void AddTestAttachment(string filePath, string? description = null)
Parameters
filePath
stringRelative or absolute file path to attachment
description
stringOptional description of attachment
Write(bool)
Write the string representation of a boolean value to the current result
public static void Write(bool value)
Parameters
value
bool
Write(char)
Write a char to the current result
public static void Write(char value)
Parameters
value
char
Write(char[]?)
Write a char array to the current result
public static void Write(char[]? value)
Parameters
value
char[]
Write(decimal)
Write the string representation of a decimal value to the current result
public static void Write(decimal value)
Parameters
value
decimal
Write(double)
Write the string representation of a double to the current result
public static void Write(double value)
Parameters
value
double
Write(int)
Write the string representation of an Int32 value to the current result
public static void Write(int value)
Parameters
value
int
Write(long)
Write the string representation of an Int64 value to the current result
public static void Write(long value)
Parameters
value
long
Write(object?)
Write the string representation of an object to the current result
public static void Write(object? value)
Parameters
value
object
Write(float)
Write the string representation of a Single value to the current result
public static void Write(float value)
Parameters
value
float
Write(string?)
Write a string to the current result
public static void Write(string? value)
Parameters
value
string
Write(string, object?)
Write a formatted string to the current result
public static void Write(string format, object? arg1)
Parameters
Write(string, object?, object?)
Write a formatted string to the current result
public static void Write(string format, object? arg1, object? arg2)
Parameters
Write(string, object?, object?, object?)
Write a formatted string to the current result
public static void Write(string format, object? arg1, object? arg2, object? arg3)
Parameters
Write(string, params object?[])
Write a formatted string to the current result
public static void Write(string format, params object?[] args)
Parameters
Write(uint)
Write the string representation of a UInt32 value to the current result
[CLSCompliant(false)]
public static void Write(uint value)
Parameters
value
uint
Write(ulong)
Write the string representation of a UInt64 value to the current result
[CLSCompliant(false)]
public static void Write(ulong value)
Parameters
value
ulong
WriteLine()
Write a line terminator to the current result
public static void WriteLine()
WriteLine(bool)
Write the string representation of a boolean value to the current result followed by a line terminator
public static void WriteLine(bool value)
Parameters
value
bool
WriteLine(char)
Write a char to the current result followed by a line terminator
public static void WriteLine(char value)
Parameters
value
char
WriteLine(char[]?)
Write a char array to the current result followed by a line terminator
public static void WriteLine(char[]? value)
Parameters
value
char[]
WriteLine(decimal)
Write the string representation of a decimal value to the current result followed by a line terminator
public static void WriteLine(decimal value)
Parameters
value
decimal
WriteLine(double)
Write the string representation of a double to the current result followed by a line terminator
public static void WriteLine(double value)
Parameters
value
double
WriteLine(int)
Write the string representation of an Int32 value to the current result followed by a line terminator
public static void WriteLine(int value)
Parameters
value
int
WriteLine(long)
Write the string representation of an Int64 value to the current result followed by a line terminator
public static void WriteLine(long value)
Parameters
value
long
WriteLine(object?)
Write the string representation of an object to the current result followed by a line terminator
public static void WriteLine(object? value)
Parameters
value
object
WriteLine(float)
Write the string representation of a Single value to the current result followed by a line terminator
public static void WriteLine(float value)
Parameters
value
float
WriteLine(string?)
Write a string to the current result followed by a line terminator
public static void WriteLine(string? value)
Parameters
value
string
WriteLine(string, object?)
Write a formatted string to the current result followed by a line terminator
public static void WriteLine(string format, object? arg1)
Parameters
WriteLine(string, object?, object?)
Write a formatted string to the current result followed by a line terminator
public static void WriteLine(string format, object? arg1, object? arg2)
Parameters
WriteLine(string, object?, object?, object?)
Write a formatted string to the current result followed by a line terminator
public static void WriteLine(string format, object? arg1, object? arg2, object? arg3)
Parameters
WriteLine(string, params object?[])
Write a formatted string to the current result followed by a line terminator
public static void WriteLine(string format, params object?[] args)
Parameters
WriteLine(uint)
Write the string representation of a UInt32 value to the current result followed by a line terminator
[CLSCompliant(false)]
public static void WriteLine(uint value)
Parameters
value
uint
WriteLine(ulong)
Write the string representation of a UInt64 value to the current result followed by a line terminator
[CLSCompliant(false)]
public static void WriteLine(ulong value)
Parameters
value
ulong