Class TestCaseData
The TestCaseData class represents a set of arguments and other parameter info to be used for a parameterized test case. It is derived from TestCaseParameters and adds a fluent syntax for use in initializing the test case.
Inheritance
Inherited Members
Namespace: NUnit.Framework
Assembly: nunit.framework.dll
Syntax
public class TestCaseData : TestCaseParameters, ITestCaseData, ITestData, IApplyToTest
Constructors
View SourceTestCaseData(object?)
Initializes a new instance of the TestCaseData class.
Declaration
public TestCaseData(object? arg)
Parameters
| Type | Name | Description |
|---|---|---|
| object | arg | The argument. |
TestCaseData(object?, object?)
Initializes a new instance of the TestCaseData class.
Declaration
public TestCaseData(object? arg1, object? arg2)
Parameters
| Type | Name | Description |
|---|---|---|
| object | arg1 | The first argument. |
| object | arg2 | The second argument. |
TestCaseData(object?, object?, object?)
Initializes a new instance of the TestCaseData class.
Declaration
public TestCaseData(object? arg1, object? arg2, object? arg3)
Parameters
| Type | Name | Description |
|---|---|---|
| object | arg1 | The first argument. |
| object | arg2 | The second argument. |
| object | arg3 | The third argument. |
TestCaseData(params object?[]?)
Initializes a new instance of the TestCaseData class.
Declaration
public TestCaseData(params object?[]? args)
Parameters
| Type | Name | Description |
|---|---|---|
| object[] | args | The arguments. |
Methods
View SourceExplicit()
Marks the test case as explicit.
Declaration
public TestCaseData Explicit()
Returns
| Type | Description |
|---|---|
| TestCaseData |
Explicit(string)
Marks the test case as explicit, specifying the reason.
Declaration
public TestCaseData Explicit(string reason)
Parameters
| Type | Name | Description |
|---|---|---|
| string | reason |
Returns
| Type | Description |
|---|---|
| TestCaseData |
Ignore(string)
Ignores this TestCase, specifying the reason.
Declaration
public IgnoredTestCaseData Ignore(string reason)
Parameters
| Type | Name | Description |
|---|---|---|
| string | reason | The reason. |
Returns
| Type | Description |
|---|---|
| IgnoredTestCaseData |
Returns(object?)
Sets the expected result for the test
Declaration
public TestCaseData Returns(object? result)
Parameters
| Type | Name | Description |
|---|---|---|
| object | result | The expected result |
Returns
| Type | Description |
|---|---|
| TestCaseData | A modified TestCaseData |
SetArgDisplayNames(params object?[]?)
Sets the list of display names to use as the parameters in the test name. Objects are formatted using the same logic as default test names.
Declaration
public TestCaseData SetArgDisplayNames(params object?[]? displayNames)
Parameters
| Type | Name | Description |
|---|---|---|
| object[] | displayNames |
Returns
| Type | Description |
|---|---|
| TestCaseData | The modified TestCaseData instance |
Examples
TestCaseData testCase = new TestCaseData(args)
.SetArgDisplayNames(testData.Name, testData.Gender, testData.Age);
View Source
SetArgDisplayNames(params string[]?)
Sets the list of display names to use as the parameters in the test name.
Declaration
public TestCaseData SetArgDisplayNames(params string[]? displayNames)
Parameters
| Type | Name | Description |
|---|---|---|
| string[] | displayNames |
Returns
| Type | Description |
|---|---|
| TestCaseData | The modified TestCaseData instance |
Examples
TestCaseData testCase = new TestCaseData(args)
.SetArgDisplayNames("arg1DisplayName", "arg2DisplayName");
View Source
SetCategory(string)
Applies a category to the test
Declaration
public TestCaseData SetCategory(string category)
Parameters
| Type | Name | Description |
|---|---|---|
| string | category |
Returns
| Type | Description |
|---|---|
| TestCaseData |
SetDescription(string)
Sets the description for the test case being constructed.
Declaration
public TestCaseData SetDescription(string description)
Parameters
| Type | Name | Description |
|---|---|---|
| string | description | The description. |
Returns
| Type | Description |
|---|---|
| TestCaseData | The modified TestCaseData instance. |
SetName(string?)
Sets the name of the test case
Declaration
public TestCaseData SetName(string? name)
Parameters
| Type | Name | Description |
|---|---|---|
| string | name |
Returns
| Type | Description |
|---|---|
| TestCaseData | The modified TestCaseData instance |
Remarks
Consider using SetArgDisplayNames(params string[]?) for setting argument values in the test name. SetArgDisplayNames(params string[]?) allows you to specify the display names for parameters directly without needing to use tokens like {m}.
SetProperty(string, double)
Applies a named property to the test
Declaration
public TestCaseData SetProperty(string propName, double propValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | propName | |
| double | propValue |
Returns
| Type | Description |
|---|---|
| TestCaseData |
SetProperty(string, int)
Applies a named property to the test
Declaration
public TestCaseData SetProperty(string propName, int propValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | propName | |
| int | propValue |
Returns
| Type | Description |
|---|---|
| TestCaseData |
SetProperty(string, string)
Applies a named property to the test
Declaration
public TestCaseData SetProperty(string propName, string propValue)
Parameters
| Type | Name | Description |
|---|---|---|
| string | propName | |
| string | propValue |
Returns
| Type | Description |
|---|---|
| TestCaseData |