Skip to content

Commit b5a0a4c

Browse files
authored
Document MSTest 3.8 TestContext support for ClassCleanup/AssemblyCleanup (#44140)
* Document MSTest 3.8 TestContext support for ClassCleanup/AssemblyCleanup * Add back
1 parent 92b3191 commit b5a0a4c

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

docs/core/testing/mstest-analyzers/mstest0011.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Methods marked with `[ClassCleanup]` should follow the following layout to be va
3838
- it should not be `async void`
3939
- it should not be a special method (finalizer, operator...).
4040
- it should not be generic
41-
- it should not take any parameter
41+
- it should not take any parameter, or starting with MSTest 3.8, it can have a single `TestContext` parameter
4242
- return type should be `void`, `Task` or `ValueTask`
4343
- `InheritanceBehavior.BeforeEachDerivedClass` attribute parameter should be specified if the class is `abstract`.
4444
- `InheritanceBehavior.BeforeEachDerivedClass` attribute parameter should not be specified if the class is `sealed`.

docs/core/testing/mstest-analyzers/mstest0013.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Methods marked with `[AssemblyCleanup]` should follow the following layout to be
3838
- it should not be `async void`
3939
- it should not be a special method (finalizer, operator...).
4040
- it should not be generic
41-
- it should not take any parameter
41+
- it should not take any parameter, or starting with MSTest 3.8, it can have a single `TestContext` parameter
4242
- return type should be `void`, `Task` or `ValueTask`
4343

4444
The type declaring these methods should also respect the following rules:

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ Setup and cleanup that is common to multiple tests can be extracted to a separat
189189

190190
[AssemblyInitialize](<xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyInitializeAttribute>) is called right after your assembly is loaded and [AssemblyCleanup](<xref:Microsoft.VisualStudio.TestTools.UnitTesting.AssemblyCleanupAttribute>) is called right before your assembly is unloaded.
191191

192-
The methods marked with these attributes should be defined as `static void`, `static Task` or `static ValueTask` (starting with MSTest v3.3), in a `TestClass`, and appear only once. The initialize part requires one argument of type [TestContext](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext) and the cleanup no argument.
192+
The methods marked with these attributes should be defined as `static void`, `static Task` or `static ValueTask` (starting with MSTest v3.3), in a `TestClass`, and appear only once. The initialize part requires one parameter of type [TestContext](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext) and the cleanup either no parameters, or starting with MSTest 3.8 can have one parameter of type [TestContext](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext).
193193

194194
```csharp
195195
[TestClass]
@@ -201,7 +201,7 @@ public class MyTestClass
201201
}
202202

203203
[AssemblyCleanup]
204-
public static void AssemblyCleanup()
204+
public static void AssemblyCleanup() // Starting with MSTest 3.8, it can be AssemblyCleanup(TestContext testContext)
205205
{
206206
}
207207
}
@@ -217,7 +217,7 @@ public class MyOtherTestClass
217217
}
218218

219219
[AssemblyCleanup]
220-
public static async Task AssemblyCleanup()
220+
public static async Task AssemblyCleanup() // Starting with MSTest 3.8, it can be AssemblyCleanup(TestContext testContext)
221221
{
222222
}
223223
}
@@ -231,7 +231,7 @@ It's possible to control the inheritance behavior: only for current class using
231231

232232
It's also possible to configure whether the class cleanup should be run at the end of the class or at the end of the assembly.
233233

234-
The methods marked with these attributes should be defined as `static void`, `static Task` or `static ValueTask` (starting with MSTest v3.3), in a `TestClass`, and appear only once. The initialize part requires one argument of type [TestContext](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext) and the cleanup no argument.
234+
The methods marked with these attributes should be defined as `static void`, `static Task` or `static ValueTask` (starting with MSTest v3.3), in a `TestClass`, and appear only once. The initialize part requires one parameter of type [TestContext](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext) and the cleanup either no parameters, or starting with MSTest 3.8 can have one parameter of type [TestContext](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestContext).
235235

236236
```csharp
237237
[TestClass]
@@ -243,7 +243,7 @@ public class MyTestClass
243243
}
244244

245245
[ClassCleanup]
246-
public static void ClassCleanup()
246+
public static void ClassCleanup() // Starting with MSTest 3.8, it can be ClassCleanup(TestContext testContext)
247247
{
248248
}
249249
}
@@ -259,7 +259,7 @@ public class MyOtherTestClass
259259
}
260260

261261
[ClassCleanup]
262-
public static async Task ClassCleanup()
262+
public static async Task ClassCleanup() // Starting with MSTest 3.8, it can be ClassCleanup(TestContext testContext)
263263
{
264264
}
265265
}

0 commit comments

Comments
 (0)