Search Results for

    Show / Hide Table of Contents

    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.

    Inheritance
    object
    TestContext
    Inherited Members
    object.GetType()
    object.MemberwiseClone()
    object.ToString()
    object.Equals(object)
    object.Equals(object, object)
    object.ReferenceEquals(object, object)
    object.GetHashCode()
    Namespace: NUnit.Framework
    Assembly: nunit.framework.dll
    Syntax
    public class TestContext

    Constructors

    View Source

    TestContext(TestExecutionContext)

    Construct a TestContext for an ExecutionContext

    Declaration
    public TestContext(TestExecutionContext testExecutionContext)
    Parameters
    Type Name Description
    TestExecutionContext testExecutionContext

    The ExecutionContext to adapt

    Fields

    View Source

    Error

    Gets a TextWriter that will send output directly to Console.Error

    Declaration
    public static TextWriter Error
    Field Value
    Type Description
    TextWriter
    View Source

    Parameters

    TestParameters object holds parameters for the test run, if any are specified

    Declaration
    public static readonly TestParameters Parameters
    Field Value
    Type Description
    TestParameters
    View Source

    Progress

    Gets a TextWriter for use in displaying immediate progress messages

    Declaration
    public static readonly TextWriter Progress
    Field Value
    Type Description
    TextWriter

    Properties

    View Source

    AssertCount

    Gets the number of assertions executed up to this point in the test.

    Declaration
    public int AssertCount { get; }
    Property Value
    Type Description
    int
    View Source

    CancellationToken

    Gets the CancellationToken for the test case.

    Declaration
    public CancellationToken CancellationToken { get; }
    Property Value
    Type Description
    CancellationToken
    View Source

    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.

    Declaration
    public static TestContext CurrentContext { get; }
    Property Value
    Type Description
    TestContext
    View Source

    CurrentRepeatCount

    Get the number of times the current Test has been repeated when using the RetryAttribute or RepeatAttribute.

    Declaration
    public int CurrentRepeatCount { get; }
    Property Value
    Type Description
    int
    View Source

    Out

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

    Declaration
    public static TextWriter Out { get; }
    Property Value
    Type Description
    TextWriter
    View Source

    Random

    Gets the random generator.

    Declaration
    public Randomizer Random { get; }
    Property Value
    Type Description
    Randomizer

    The random generator.

    View Source

    Result

    Gets a Representation of the TestResult for the current test.

    Declaration
    public TestContext.ResultAdapter Result { get; }
    Property Value
    Type Description
    TestContext.ResultAdapter
    View Source

    Test

    Get a representation of the current test.

    Declaration
    public TestContext.TestAdapter Test { get; }
    Property Value
    Type Description
    TestContext.TestAdapter
    View Source

    TestDirectory

    Gets the directory containing the current test assembly.

    Declaration
    public string TestDirectory { get; }
    Property Value
    Type Description
    string
    View Source

    WorkDirectory

    Gets the directory to be used for outputting files created by this test run.

    Declaration
    public string WorkDirectory { get; }
    Property Value
    Type Description
    string
    View Source

    WorkerId

    Gets the unique name of the Worker that is executing this test.

    Declaration
    public string? WorkerId { get; }
    Property Value
    Type Description
    string

    Methods

    View Source

    AddFormatter(ValueFormatterFactory)

    This method adds a new ValueFormatterFactory to the chain of responsibility used for formatting values in messages. The scope of the change is the current TestContext.

    Declaration
    public static void AddFormatter(ValueFormatterFactory formatterFactory)
    Parameters
    Type Name Description
    ValueFormatterFactory formatterFactory

    The factory delegate

    View Source

    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.

    Declaration
    public static void AddFormatter<TSupported>(ValueFormatter formatter)
    Parameters
    Type Name Description
    ValueFormatter formatter

    The ValueFormatter delegate

    Type Parameters
    Name Description
    TSupported

    The type supported by this formatter

    View Source

    AddTestAttachment(string, string?)

    Attach a file to the current test result

    Declaration
    public static void AddTestAttachment(string filePath, string? description = null)
    Parameters
    Type Name Description
    string filePath

    Relative or absolute file path to attachment

    string description

    Optional description of attachment

    View Source

    Write(bool)

    Write the string representation of a boolean value to the current result

    Declaration
    public static void Write(bool value)
    Parameters
    Type Name Description
    bool value
    View Source

    Write(char)

    Write a char to the current result

    Declaration
    public static void Write(char value)
    Parameters
    Type Name Description
    char value
    View Source

    Write(char[]?)

    Write a char array to the current result

    Declaration
    public static void Write(char[]? value)
    Parameters
    Type Name Description
    char[] value
    View Source

    Write(decimal)

    Write the string representation of a decimal value to the current result

    Declaration
    public static void Write(decimal value)
    Parameters
    Type Name Description
    decimal value
    View Source

    Write(double)

    Write the string representation of a double to the current result

    Declaration
    public static void Write(double value)
    Parameters
    Type Name Description
    double value
    View Source

    Write(int)

    Write the string representation of an Int32 value to the current result

    Declaration
    public static void Write(int value)
    Parameters
    Type Name Description
    int value
    View Source

    Write(long)

    Write the string representation of an Int64 value to the current result

    Declaration
    public static void Write(long value)
    Parameters
    Type Name Description
    long value
    View Source

    Write(object?)

    Write the string representation of an object to the current result

    Declaration
    public static void Write(object? value)
    Parameters
    Type Name Description
    object value
    View Source

    Write(float)

    Write the string representation of a Single value to the current result

    Declaration
    public static void Write(float value)
    Parameters
    Type Name Description
    float value
    View Source

    Write(string?)

    Write a string to the current result

    Declaration
    public static void Write(string? value)
    Parameters
    Type Name Description
    string value
    View Source

    Write(string, object?)

    Write a formatted string to the current result

    Declaration
    public static void Write(string format, object? arg1)
    Parameters
    Type Name Description
    string format
    object arg1
    View Source

    Write(string, object?, object?)

    Write a formatted string to the current result

    Declaration
    public static void Write(string format, object? arg1, object? arg2)
    Parameters
    Type Name Description
    string format
    object arg1
    object arg2
    View Source

    Write(string, object?, object?, object?)

    Write a formatted string to the current result

    Declaration
    public static void Write(string format, object? arg1, object? arg2, object? arg3)
    Parameters
    Type Name Description
    string format
    object arg1
    object arg2
    object arg3
    View Source

    Write(string, params object?[])

    Write a formatted string to the current result

    Declaration
    public static void Write(string format, params object?[] args)
    Parameters
    Type Name Description
    string format
    object[] args
    View Source

    Write(uint)

    Write the string representation of a UInt32 value to the current result

    Declaration
    [CLSCompliant(false)]
    public static void Write(uint value)
    Parameters
    Type Name Description
    uint value
    View Source

    Write(ulong)

    Write the string representation of a UInt64 value to the current result

    Declaration
    [CLSCompliant(false)]
    public static void Write(ulong value)
    Parameters
    Type Name Description
    ulong value
    View Source

    WriteLine()

    Write a line terminator to the current result

    Declaration
    public static void WriteLine()
    View Source

    WriteLine(bool)

    Write the string representation of a boolean value to the current result followed by a line terminator

    Declaration
    public static void WriteLine(bool value)
    Parameters
    Type Name Description
    bool value
    View Source

    WriteLine(char)

    Write a char to the current result followed by a line terminator

    Declaration
    public static void WriteLine(char value)
    Parameters
    Type Name Description
    char value
    View Source

    WriteLine(char[]?)

    Write a char array to the current result followed by a line terminator

    Declaration
    public static void WriteLine(char[]? value)
    Parameters
    Type Name Description
    char[] value
    View Source

    WriteLine(decimal)

    Write the string representation of a decimal value to the current result followed by a line terminator

    Declaration
    public static void WriteLine(decimal value)
    Parameters
    Type Name Description
    decimal value
    View Source

    WriteLine(double)

    Write the string representation of a double to the current result followed by a line terminator

    Declaration
    public static void WriteLine(double value)
    Parameters
    Type Name Description
    double value
    View Source

    WriteLine(int)

    Write the string representation of an Int32 value to the current result followed by a line terminator

    Declaration
    public static void WriteLine(int value)
    Parameters
    Type Name Description
    int value
    View Source

    WriteLine(long)

    Write the string representation of an Int64 value to the current result followed by a line terminator

    Declaration
    public static void WriteLine(long value)
    Parameters
    Type Name Description
    long value
    View Source

    WriteLine(object?)

    Write the string representation of an object to the current result followed by a line terminator

    Declaration
    public static void WriteLine(object? value)
    Parameters
    Type Name Description
    object value
    View Source

    WriteLine(float)

    Write the string representation of a Single value to the current result followed by a line terminator

    Declaration
    public static void WriteLine(float value)
    Parameters
    Type Name Description
    float value
    View Source

    WriteLine(string?)

    Write a string to the current result followed by a line terminator

    Declaration
    public static void WriteLine(string? value)
    Parameters
    Type Name Description
    string value
    View Source

    WriteLine(string, object?)

    Write a formatted string to the current result followed by a line terminator

    Declaration
    public static void WriteLine(string format, object? arg1)
    Parameters
    Type Name Description
    string format
    object arg1
    View Source

    WriteLine(string, object?, object?)

    Write a formatted string to the current result followed by a line terminator

    Declaration
    public static void WriteLine(string format, object? arg1, object? arg2)
    Parameters
    Type Name Description
    string format
    object arg1
    object arg2
    View Source

    WriteLine(string, object?, object?, object?)

    Write a formatted string to the current result followed by a line terminator

    Declaration
    public static void WriteLine(string format, object? arg1, object? arg2, object? arg3)
    Parameters
    Type Name Description
    string format
    object arg1
    object arg2
    object arg3
    View Source

    WriteLine(string, params object?[])

    Write a formatted string to the current result followed by a line terminator

    Declaration
    public static void WriteLine(string format, params object?[] args)
    Parameters
    Type Name Description
    string format
    object[] args
    View Source

    WriteLine(uint)

    Write the string representation of a UInt32 value to the current result followed by a line terminator

    Declaration
    [CLSCompliant(false)]
    public static void WriteLine(uint value)
    Parameters
    Type Name Description
    uint value
    View Source

    WriteLine(ulong)

    Write the string representation of a UInt64 value to the current result followed by a line terminator

    Declaration
    [CLSCompliant(false)]
    public static void WriteLine(ulong value)
    Parameters
    Type Name Description
    ulong value
    • View Source
    In this article
    Back to top Generated by DocFX | Copyright (c) 2018- The NUnit Project - Licensed under CC BY-NC-SA 4.0