Skip to content

Commit d00a435

Browse files
authored
Fix MSTest docs (#51751)
Address review comments post merge
1 parent b2e1484 commit d00a435

File tree

2 files changed

+25
-27
lines changed

2 files changed

+25
-27
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ The `Workers` property specifies the maximum number of threads for parallel exec
145145
> You can also configure parallelization through [runsettings](unit-testing-mstest-configure.md#mstest-element) or [testconfig.json](unit-testing-mstest-configure.md#testconfigjson) without modifying code.
146146
147147
> [!TIP]
148-
> Enable parallelization at the assembly level by default, even if many tests currently require sequential execution. This approach encourages writing new tests that support parallel execution from the start. Use the [MSTEST0001](mstest-analyzers/mstest0001.md) analyzer to ensure that every test class explicitly declares its parallelization intent, which forces you to review whether each class safely supports concurrent execution. Often, excluding just a few classes or methods with `DoNotParallelize` is sufficient, allowing the majority of your tests to run in parallel for significantly faster test execution.
148+
> Enable parallelization at the assembly level by default, even if many tests currently require sequential execution. This approach encourages writing new tests that support parallel execution from the start. Use the [MSTEST0001](mstest-analyzers/mstest0001.md) analyzer to ensure that the assembly explicitly declares its parallelization intent with `[assembly: Parallelize]` or `[assembly: DoNotParallelize]`. Once parallelization is enabled, review each test class to determine whether it safely supports concurrent execution. Often, excluding just a few classes or methods with `DoNotParallelize` is sufficient, allowing the majority of your tests to run in parallel for significantly faster test execution.
149149
150150
### `DoNotParallelizeAttribute`
151151

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

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,12 @@ MSTest provides several attributes for data-driven testing:
1818
|-----------|----------|----------|
1919
| [`DataRow`](#datarowattribute) | Inline test data | Simple, static test cases |
2020
| [`DynamicData`](#dynamicdataattribute) | Data from methods, properties, or fields | Complex or computed test data |
21-
| [`TestDataRow<T>`](#testdatarow) | Enhanced data with metadata | Test cases needing display names or categories |
2221
| [`DataSource`](#datasourceattribute) | External data files or databases | Legacy scenarios with external data sources |
23-
| [`ITestDataSource`](#itestdatasource) | Custom data source attributes | Fully custom data-driven scenarios |
22+
23+
MSTest also provides the following types to extend data-driven scenarios:
24+
25+
- [`TestDataRow<T>`](#testdatarow): A return type for `ITestDataSource` implementations (including `DynamicData`) that adds metadata support such as display names, categories, and ignore messages to individual test cases.
26+
- [`ITestDataSource`](#itestdatasource): An interface you can implement on a custom attribute to create fully custom data source attributes.
2427

2528
> [!TIP]
2629
> For combinatorial testing (testing all combinations of multiple parameter sets), use the open-source [Combinatorial.MSTest](https://www.nuget.org/packages/Combinatorial.MSTest) NuGet package. This community-maintained package is [available on GitHub](https://github.com/Youssef1313/Combinatorial.MSTest) but isn't maintained by Microsoft.
@@ -237,10 +240,10 @@ Specify a different class using the type parameter:
237240
```csharp
238241
public class TestDataProvider
239242
{
240-
public static IEnumerable<object[]> GetTestData()
243+
public static IEnumerable<(int, string)> GetTestData()
241244
{
242-
yield return new object[] { 1, "first" };
243-
yield return new object[] { 2, "second" };
245+
yield return (1, "first");
246+
yield return (2, "second");
244247
}
245248
}
246249

@@ -273,10 +276,10 @@ public class DynamicDataDisplayNameExample
273276
Assert.IsTrue(value1 > 0);
274277
}
275278

276-
public static IEnumerable<object[]> GetTestData()
279+
public static IEnumerable<(int, string)> GetTestData()
277280
{
278-
yield return new object[] { 1, "first" };
279-
yield return new object[] { 2, "second" };
281+
yield return (1, "first");
282+
yield return (2, "second");
280283
}
281284

282285
public static string GetDisplayName(MethodInfo methodInfo, object[] data)
@@ -307,10 +310,10 @@ public class IgnoreDynamicDataExample
307310
// All test cases from GetTestData are skipped
308311
}
309312

310-
public static IEnumerable<object[]> GetTestData()
313+
public static IEnumerable<(int, string)> GetTestData()
311314
{
312-
yield return new object[] { 1, "first" };
313-
yield return new object[] { 2, "second" };
315+
yield return (1, "first");
316+
yield return (2, "second");
314317
}
315318
}
316319
```
@@ -340,20 +343,20 @@ public class TestDataRowExample
340343
Assert.IsTrue(value1 > 0);
341344
}
342345

343-
public static IEnumerable<TestDataRow> GetTestDataRows()
346+
public static IEnumerable<TestDataRow<(int, string)>> GetTestDataRows()
344347
{
345-
yield return new TestDataRow((1, "first"))
348+
yield return new TestDataRow<(int, string)>((1, "first"))
346349
{
347350
DisplayName = "Test Case 1: Basic scenario",
348351
};
349352

350-
yield return new TestDataRow((2, "second"))
353+
yield return new TestDataRow<(int, string)>((2, "second"))
351354
{
352355
DisplayName = "Test Case 2: Edge case",
353356
TestCategories = ["HighPriority", "Critical"],
354357
};
355358

356-
yield return new TestDataRow((3, "third"))
359+
yield return new TestDataRow<(int, string)>((3, "third"))
357360
{
358361
IgnoreMessage = "Not yet implemented",
359362
};
@@ -511,27 +514,22 @@ For most scenarios, the default `Auto` behavior provides the best balance. Consi
511514
public class UnfoldingExample
512515
{
513516
[TestMethod(UnfoldingStrategy = TestDataSourceUnfoldingStrategy.Unfold)] // That's the default behavior
514-
[DataRow(1)]
515-
[DataRow(2)]
516-
[DataRow(3)]
517+
[DataRow(1, "one")]
518+
[DataRow(2, "two")]
519+
[DataRow(3, "three")]
517520
public void TestMethodWithUnfolding(int value, string text)
518521
{
519522
// Each test case appears individually in Test Explorer
520523
}
521524

522525
[TestMethod(UnfoldingStrategy = TestDataSourceUnfoldingStrategy.Fold)]
523-
[DynamicData(nameof(GetData))]
526+
[DataRow(1, "one")]
527+
[DataRow(2, "two")]
528+
[DataRow(3, "three")]
524529
public void TestMethodWithFolding(int value, string text)
525530
{
526531
// All test cases appear as a single collapsed node
527532
}
528-
529-
public static IEnumerable<(int, string)> GetData()
530-
{
531-
yield return (1, "one");
532-
yield return (2, "two");
533-
yield return (3, "three");
534-
}
535533
}
536534
```
537535

0 commit comments

Comments
 (0)