Skip to content

Commit 8c3d957

Browse files
Evangelinkgewarren
andauthored
Apply suggestions from code review
Co-authored-by: Genevieve Warren <[email protected]>
1 parent 94c2878 commit 8c3d957

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

docs/core/testing/unit-testing-mstest-writing-tests-testcontext.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ ms.date: 11/12/2024
88

99
# The `TestContext` class
1010

11-
The `TestContext` class provides contextual information and support for test execution, making it easier to retrieve information about the test run and manipulate aspects of the environment. It's defined in the `Microsoft.VisualStudio.TestTools.UnitTesting` namespace and is available when using the MSTest Framework.
11+
The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext> class provides contextual information and support for test execution, making it easier to retrieve information about the test run and manipulate aspects of the environment. It's defined in the <xref:Microsoft.VisualStudio.TestTools.UnitTesting> namespace and is available when using the MSTest Framework.
1212

1313
## Accessing the `TestContext` object
1414

15-
The `TestContext` object is available in the following contexts:
15+
The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext> object is available in the following contexts:
1616

1717
- As a parameter to `[AssemblyInitialize]` and `[ClassInitialize]` methods. In this context, the properties related to the test run are not available.
1818
- As a property of a test class. In this context, the properties related to the test run are available.
@@ -44,7 +44,7 @@ public class MyTestClass
4444
}
4545
```
4646

47-
or with MSTest 3.6+
47+
Or with MSTest 3.6+:
4848

4949
```csharp
5050
[TestClass]
@@ -79,7 +79,7 @@ public class MyTestClass
7979

8080
## The `TestContext` members
8181

82-
The `TestContext` class provides properties about the test run along with methods to manipulate the test environment. In this section, we will cover the most commonly used properties and methods.
82+
The `TestContext` class provides properties about the test run along with methods to manipulate the test environment. This section covers the most commonly used properties and methods.
8383

8484
### Test run information
8585

@@ -98,13 +98,13 @@ In MSTest 3.7 and later, the `TestContext` class also provides new properties he
9898

9999
- `TestData` – the data that will be provided to the parameterized test method or `null` if the test is not parameterized.
100100
- `TestDisplayName` - the display name of the test method.
101-
- `TestException` - the exception thrown by either the test method or test initialize or `null` if the test method did not throw an exception.
101+
- `TestException` - the exception thrown by either the test method or test initialize, or `null` if the test method did not throw an exception.
102102

103103
### Data-driven tests
104104

105105
`TestContext` is essential for data-driven testing in MSTest. It 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).
106106

107-
Assuming the following CSV file `TestData.csv`:
107+
Consider the following CSV file `TestData.csv`:
108108

109109
```csv
110110
Number,Name
@@ -150,7 +150,7 @@ namespace YourNamespace
150150

151151
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.
152152

153-
### Storing and Retrieving Runtime Data
153+
### Store and retrieve runtime data
154154

155155
You can use `TestContext.Properties` to store custom key-value pairs that can be accessed across different methods in the same test session.
156156

@@ -159,9 +159,9 @@ TestContext.Properties["MyKey"] = "MyValue";
159159
string value = TestContext.Properties["MyKey"]?.ToString();
160160
```
161161

162-
### Associating data to a test
162+
### Associate data to a test
163163

164-
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 (e.g., log files, screenshots, or data files) that you want to attach to the test results.
164+
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.
165165

166166
```csharp
167167
[TestMethod]

docs/core/testing/unit-testing-mstest-writing-tests.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ MSTest assertions are divided into the following classes:
4949

5050
## The `TestContext` class
5151

52-
The `TestContext` class provides contextual information and support for test execution, making it easier to retrieve information about the test run and manipulate aspects of the environment. It's defined in the `Microsoft.VisualStudio.TestTools.UnitTesting` namespace and is available when using the MSTest Framework.
52+
The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext> class provides contextual information and support for test execution, making it easier to retrieve information about the test run and manipulate aspects of the environment. It's defined in the <xref:Microsoft.VisualStudio.TestTools.UnitTesting> namespace and is available when using the MSTest Framework.
5353

54-
You can learn about [accessing the `TestContext` object](./unit-testing-mstest-writing-tests-testcontext.md#accessing-the-testcontext-object) or [the `TestContext` members](./unit-testing-mstest-writing-tests-testcontext.md#the-testcontext-members).
54+
For more information, see [Accessing the `TestContext` object](./unit-testing-mstest-writing-tests-testcontext.md#accessing-the-testcontext-object) or [The `TestContext` members](./unit-testing-mstest-writing-tests-testcontext.md#the-testcontext-members).
5555

5656
## Testing private members
5757

0 commit comments

Comments
 (0)