Table of Contents

Class UniqueIDGenerator

Namespace
Xunit.Sdk

Generates unique IDs from multiple string inputs. Used to compute the unique IDs that are used inside the test framework.

public sealed class UniqueIDGenerator : IDisposable
Inheritance
UniqueIDGenerator
Implements
Inherited Members
Extension Methods

Constructors

UniqueIDGenerator()

Initializes a new instance of the UniqueIDGenerator class.

public UniqueIDGenerator()

Methods

Add(string)

Add a string value into the unique ID computation.

public void Add(string value)

Parameters

value string

The value to be added to the unique ID computation

Compute()

Compute the unique ID for the given input values. Note that once the unique ID has been computed, no further Add(string) operations will be allowed.

public string Compute()

Returns

string

The computed unique ID

Dispose()

Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.

public void Dispose()

ForAssembly(string, string?)

Computes a unique ID for a test assembly.

public static string ForAssembly(string assemblyPath, string? configFilePath)

Parameters

assemblyPath string

The assembly path

configFilePath string

The optional configuration file path

Returns

string

The computed unique ID for the assembly

ForTest(string, int)

Computes a unique ID for a test.

public static string ForTest(string testCaseUniqueID, int testIndex)

Parameters

testCaseUniqueID string

The unique ID of the test case that this test belongs to.

testIndex int

The index of this test in the test case, typically starting with 0 (though a negative number may be used to prevent collisions with legitimate test indices).

Returns

string

ForTestCase(string, Type[]?, object?[]?)

Computes a unique ID for a test case.

public static string ForTestCase(string parentUniqueID, Type[]? testMethodGenericTypes, object?[]? testMethodArguments)

Parameters

parentUniqueID string

The unique ID of the parent in the hierarchy; typically the test method unique ID, but may also be the test class or test collection unique ID, when test method (and possibly test class) don't exist.

testMethodGenericTypes Type[]

The test method's generic types

testMethodArguments object[]

The test method's arguments

Returns

string

The computed unique ID for the test case

ForTestClass(string, string?)

Computes a unique ID for a test class.

public static string? ForTestClass(string testCollectionUniqueID, string? className)

Parameters

testCollectionUniqueID string

The unique ID of the parent test collection for the test class

className string

The optional fully qualified type name of the test class

Returns

string

The computed unique ID for the test class (may return null if className is null)

ForTestCollection(string, string, string?)

Computes a unique ID for a test collection.

public static string ForTestCollection(string assemblyUniqueID, string collectionDisplayName, string? collectionDefinitionClassName)

Parameters

assemblyUniqueID string

The unique ID of the assembly the test collection lives in

collectionDisplayName string

The display name of the test collection

collectionDefinitionClassName string

The optional class name that contains the test collection definition

Returns

string

The computed unique ID for the test collection

ForTestMethod(string?, string?)

Computes a unique ID for a test method.

public static string? ForTestMethod(string? testClassUniqueID, string? methodName)

Parameters

testClassUniqueID string

The unique ID of the parent test class for the test method

methodName string

The optional test method name

Returns

string

The computed unique ID for the test method (may return null if either the class unique ID or the method name is null)

ForType(Type)

Computes a unique ID for a Type.

public static string ForType(Type type)

Parameters

type Type

The type to generate an ID for

Returns

string