You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md
+14-14Lines changed: 14 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,26 +32,26 @@ The `TestContext` class provides properties about the test run along with method
32
32
33
33
The `TestContext` provides information about the test run, such as:
34
34
35
-
-`TestName` – the name of the currently executing test.
36
-
-`CurrentTestOutcome` – the result of the current test.
37
-
-`FullyQualifiedTestClassName` – the full name of the test class.
38
-
-`TestRunDirectory` – the directory where the test run is executed.
39
-
-`DeploymentDirectory` – the directory where the deployment items are located.
40
-
-`ResultsDirectory` – the directory where the test results are stored. Typically a subdirectory of the `TestRunDirectory`.
41
-
-`TestRunResultsDirectory` – the directory where the test results are stored. Typically a subdirectory of the `ResultsDirectory`.
42
-
-`TestResultsDirectory` – the directory where the test results are stored. Typically a subdirectory of the `ResultsDirectory`.
35
+
-<xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.TestName> – the name of the currently executing test.
36
+
-<xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.CurrentTestOutcome> - the result of the current test.
37
+
-<xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.FullyQualifiedTestClassName> - the full name of the test class.
38
+
-<xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.TestRunDirectory> - the directory where the test run is executed.
39
+
-<xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.DeploymentDirectory> - the directory where the deployment items are located.
40
+
-<xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.ResultsDirectory> - the directory where the test results are stored. Typically a subdirectory of the `TestRunDirectory`.
41
+
-<xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.TestRunResultsDirectory> - the directory where the test results are stored. Typically a subdirectory of the `ResultsDirectory`.
42
+
-<xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.TestResultsDirectory> - the directory where the test results are stored. Typically a subdirectory of the `ResultsDirectory`.
43
43
44
44
In MSTest 3.7 and later, the `TestContext` class also provides new properties helpful for `TestInitialize` and `TestCleanup` methods:
45
45
46
-
-`TestData` – the data that will be provided to the parameterized test method or `null` if the test is not parameterized.
47
-
-`TestDisplayName` - the display name of the test method.
48
-
-`TestException` - the exception thrown by either the test method or test initialize, or `null` if the test method did not throw an exception.
46
+
-<xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.TestData> - the data that will be provided to the parameterized test method or `null` if the test is not parameterized.
47
+
-<xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.TestDisplayName> - the display name of the test method.
48
+
-<xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.TestException> - the exception thrown by either the test method or test initialize, or `null` if the test method did not throw an exception.
49
49
50
50
### Data-driven tests
51
51
52
52
In MSTest 3.7 and later, the property `TestData` can be used to access the data for the current test during `TestInitialize` and `TestCleanup` methods.
53
53
54
-
When targeting .NET framework, the `TestContext` enables you to retrieve and set data for each iteration in a data-driven test, using properties like `DataRow` and `DataConnection` (for datasource based tests).
54
+
When targeting .NET framework, the `TestContext` enables you to retrieve and set data for each iteration in a data-driven test, using properties like `DataRow` and `DataConnection` (for [DataSource](xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataSourceAttribute)-based tests).
55
55
56
56
Consider the following CSV file `TestData.csv`:
57
57
@@ -68,7 +68,7 @@ You can use the `DataSource` attribute to read the data from the CSV file:
68
68
69
69
### Store and retrieve runtime data
70
70
71
-
You can use `TestContext.Properties` to store custom key-value pairs that can be accessed across different methods in the same test session.
71
+
You can use <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.Properties?displayProperty=nameWithType> to store custom key-value pairs that can be accessed across different methods in the same test session.
72
72
73
73
```csharp
74
74
TestContext.Properties["MyKey"] ="MyValue";
@@ -77,7 +77,7 @@ string value = TestContext.Properties["MyKey"]?.ToString();
77
77
78
78
### Associate data to a test
79
79
80
-
The `TestContext.AddResultFile` method allows you to add a file to the test results, making it available for review in the test output. This can be useful if you generate files during your test (for example, log files, screenshots, or data files) that you want to attach to the test results.
80
+
The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext.AddResultFile(System.String)?displayProperty=nameWithType> method allows you to add a file to the test results, making it available for review in the test output. This can be useful if you generate files during your test (for example, log files, screenshots, or data files) that you want to attach to the test results.
0 commit comments