-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Document more MSTest attributes and APIs #50979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR enhances the MSTest attributes documentation by adding comprehensive coverage of previously undocumented attributes and APIs. The changes focus on data-driven testing features, test lifecycle management, threading models, conditional execution, and test control mechanisms.
Key changes include:
- Addition of
DiscoverInternalsAttributedocumentation for discovering internal test classes and methods. - Comprehensive documentation of data-driven testing features including
DynamicDataAttribute,TestDataRow, andUnfoldingStrategy. - Documentation of global test lifecycle attributes (
GlobalTestInitializeandGlobalTestCleanup). - Reorganization of test execution control attributes with new sections for threading, parallelization, timeout/retry, and conditional execution attributes.
Comments suppressed due to low confidence (5)
docs/core/testing/unit-testing-mstest-writing-tests-attributes.md:415
- This list is missing Oxford commas. The style guidelines require Oxford commas in all lists. Add commas before "and" in items where multiple concepts are joined.
- <xref:Microsoft.VisualStudio.TestTools.UnitTesting.UnfoldingStrategy.Auto?displayProperty=nameWithType> (default): MSTest automatically determines whether to unfold test cases based on the number of data rows. Test cases are collapsed (folded) when there are many data rows to avoid cluttering Test Explorer, and unfolded when there are few data rows for better visibility.
- <xref:Microsoft.VisualStudio.TestTools.UnitTesting.UnfoldingStrategy.Unfold?displayProperty=nameWithType>: All test cases are expanded and shown individually in Test Explorer and TRX results. Each test case can be run independently.
- <xref:Microsoft.VisualStudio.TestTools.UnitTesting.UnfoldingStrategy.Fold?displayProperty=nameWithType>: Test cases are collapsed into a single test node. Individual test cases cannot be run independently; the entire data-driven test runs as one unit.
docs/core/testing/unit-testing-mstest-writing-tests-attributes.md:378
- The list is missing an Oxford comma. Add a comma before "and" in the last item to comply with the Markdown writing style guidelines requiring Oxford commas in all lists.
- **Custom display names**: Set a unique display name for each test case using the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestDataRow.DisplayName> property
- **Test properties**: Attach metadata to individual test cases using the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestDataRow.TestProperties> property
- **Type-safe data**: Use the generic `TestDataRow<T>` to provide strongly-typed test data
docs/core/testing/unit-testing-mstest-writing-tests-attributes.md:639
- The list is missing an Oxford comma. Add a comma before "and a delay backoff type" to comply with the Markdown writing style guidelines requiring Oxford commas in all lists.
The [Retry](xref:Microsoft.VisualStudio.TestTools.UnitTesting.RetryAttribute) attribute was introduced in MSTest 3.8. This attribute causes the test method to be retried when it fails or timeouts. It allows you to specify the maximum number of retry attempts, the time delay between retries, and a delay backoff type, which is either constant or exponential.
docs/core/testing/unit-testing-mstest-writing-tests-attributes.md:705
- Add a comma after "for example" to properly set off this introductory phrase.
You can specify which operating systems the test supports or doesn't support using the [OperatingSystems](xref:Microsoft.VisualStudio.TestTools.UnitTesting.OperatingSystems) flags enum, which includes `Windows`, `Linux`, `OSX` (macOS), and `FreeBSD`. You can combine multiple operating systems using the bitwise OR operator.
docs/core/testing/unit-testing-mstest-writing-tests-attributes.md:378
- According to the Markdown writing style guidelines, list items should be complete sentences with proper punctuation. The benefit descriptions on lines 376-378 are sentence fragments without ending punctuation. Add periods at the end of each item to make them complete sentences.
- **Custom display names**: Set a unique display name for each test case using the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestDataRow.DisplayName> property
- **Test properties**: Attach metadata to individual test cases using the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestDataRow.TestProperties> property
- **Type-safe data**: Use the generic `TestDataRow<T>` to provide strongly-typed test data
docs/core/testing/unit-testing-mstest-writing-tests-attributes.md
Outdated
Show resolved
Hide resolved
docs/core/testing/unit-testing-mstest-writing-tests-attributes.md
Outdated
Show resolved
Hide resolved
docs/core/testing/unit-testing-mstest-writing-tests-attributes.md
Outdated
Show resolved
Hide resolved
docs/core/testing/unit-testing-mstest-writing-tests-attributes.md
Outdated
Show resolved
Hide resolved
docs/core/testing/unit-testing-mstest-writing-tests-attributes.md
Outdated
Show resolved
Hide resolved
| ### `ParallelizeAttribute` | ||
| #### `UITestMethodAttribute` | ||
|
|
||
| When applied to a test method, the `UITestMethod` attribute indicates that the test method should be scheduled on the UI thread of the platform. This attribute is specifically designed for testing UWP (Universal Windows Platform) and WinUI applications that require UI thread access. |
Copilot
AI
Jan 8, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The UITestMethod attribute is not referenced with an xref cross-reference like other attributes in the document. For consistency with the rest of the document and to provide proper linking, this should be [UITestMethod](xref:Microsoft.VisualStudio.TestTools.UnitTesting.UITestMethodAttribute) or similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason the API doc related to this attribute doesn't exist. @Youssef1313 is it because the attribute is not present in all TFMs?
|
@Youssef1313 @meaghanlewis working on this doc page, I feel like the attribute grouping is too technical and it would probably be better to have something like:
|
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
|
@Evangelink I've opened a new pull request, #50980, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@Evangelink I've opened a new pull request, #50981, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@Evangelink I've opened a new pull request, #50982, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@Evangelink I've opened a new pull request, #50983, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@Evangelink I've opened a new pull request, #50984, to work on those changes. Once the pull request is ready, I'll request review from you. |
|
@Evangelink I've opened a new pull request, #50985, to work on those changes. Once the pull request is ready, I'll request review from you. |
* Initial plan * Fix ambiguous contraction in TestPropertyAttribute documentation Co-authored-by: Evangelink <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Evangelink <[email protected]>
#50982) * Initial plan * Change 'may take' to 'might take' for style compliance Co-authored-by: Evangelink <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Evangelink <[email protected]>
* Initial plan * Add periods to list items per style guide Co-authored-by: Evangelink <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Evangelink <[email protected]>
…50981) * Initial plan * Add missing using System.Reflection directive to DynamicDataDisplayName example Co-authored-by: Evangelink <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Evangelink <[email protected]>
* Initial plan * Add missing comma after "for example" on line 450 Co-authored-by: Evangelink <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Evangelink <[email protected]>
* Initial plan * Add missing Oxford commas and list punctuation Co-authored-by: Evangelink <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: Evangelink <[email protected]> Co-authored-by: Amaury Levé <[email protected]>
meaghanlewis
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These changes LGTM. I had a handful of suggestions for updated xrefs to use in place of the ones that weren't found. Also, other small language suggestions.
| } | ||
| ``` | ||
|
|
||
| The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute> also supports the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataDisplayName> property to customize how test cases appear in Test Explorer. You can specify the display name format using the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataDisplayNameDeclaringType> to reference a method that generates the display name: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute> also supports the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataDisplayName> property to customize how test cases appear in Test Explorer. You can specify the display name format using the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataDisplayNameDeclaringType> to reference a method that generates the display name: | |
| The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute> also supports the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataDisplayName> property to customize how test cases appear in Test Explorer. You can specify the display name format using the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute.DynamicDataDisplayNameDeclaringType> to reference a method that generates the display name: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these the correct xrefs?
| #### TestDataRow | ||
|
|
||
| The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestDataRow> class provides enhanced control over test data in data-driven tests. When using `IEnumerable<TestDataRow<T>>` as the return type for your dynamic data source, you can specify additional metadata for each test case, such as custom display names and test properties. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestDataRow> class provides enhanced control over test data in data-driven tests. When using `IEnumerable<TestDataRow<T>>` as the return type for your dynamic data source, you can specify additional metadata for each test case, such as custom display names and test properties. | |
| The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestDataRow-1> class provides enhanced control over test data in data-driven tests. When using `IEnumerable<TestDataRow<T>>` as the return type for your dynamic data source, you can specify additional metadata for each test case, such as custom display names and test properties. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the correct xref?
|
|
||
| `TestDataRow<T>` offers the following benefits: | ||
|
|
||
| - **Custom display names**: Set a unique display name for each test case using the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestDataRow.DisplayName> property. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| - **Custom display names**: Set a unique display name for each test case using the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestDataRow.DisplayName> property. | |
| - **Custom display names**: Set a unique display name for each test case using the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestDataRow-1.DisplayName> property. |
| `TestDataRow<T>` offers the following benefits: | ||
|
|
||
| - **Custom display names**: Set a unique display name for each test case using the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestDataRow.DisplayName> property. | ||
| - **Test properties**: Attach metadata to individual test cases using the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestDataRow.TestProperties> property. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this instead reference Test categories?
|
|
||
| ### `UnfoldingStrategy` property | ||
|
|
||
| Data-driven test attributes like <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute> and <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute> support the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.UnfoldingStrategy> property, which controls how test cases appear in Test Explorer and TRX results. This property also determines whether individual test cases can be run independently. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Data-driven test attributes like <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute> and <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute> support the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.UnfoldingStrategy> property, which controls how test cases appear in Test Explorer and TRX results. This property also determines whether individual test cases can be run independently. | |
| Data-driven test attributes like <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DataRowAttribute> and <xref:Microsoft.VisualStudio.TestTools.UnitTesting.DynamicDataAttribute> support the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TestDataSourceUnfoldingStrategy> property, which controls how test cases appear in Test Explorer and TRX results. This property also determines whether individual test cases can be run independently. |
| ## Attributes used to provide initialization and cleanups | ||
|
|
||
| Setup and cleanup that is common to multiple tests can be extracted to a separate method, and marked with one of the attributes listed below, to run it at appropriate time, for example before every test. For more information, see [Anatomy of a unit test](/previous-versions/ms182517(v=vs.110)). | ||
| Setup and cleanup that is common to multiple tests can be extracted to a separate method, and marked with one of the attributes listed below, to run it at appropriate time, for example, before every test. For more information, see [Anatomy of a unit test](/previous-versions/ms182517(v=vs.110)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| Setup and cleanup that is common to multiple tests can be extracted to a separate method, and marked with one of the attributes listed below, to run it at appropriate time, for example, before every test. For more information, see [Anatomy of a unit test](/previous-versions/ms182517(v=vs.110)). | |
| Setup and cleanup that's common to multiple tests can be extracted to a separate method and marked with one of the attributes listed in the following section, to run it at appropriate time, for example, before every test. For more information, see [Anatomy of a unit test](/previous-versions/ms182517(v=vs.110)). |
|
|
||
| > [!NOTE] | ||
| > The timeout is not guaranteed to be precise. The test will be aborted after the specified time has passed, but it may take longer before the step is cancelled. | ||
| > Multiple methods with these attributes in the assembly are allowed, but there is no guarantee of the order in which they will be executed. The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TimeoutAttribute> isn't supported on methods with the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.GlobalTestInitializeAttribute>. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| > Multiple methods with these attributes in the assembly are allowed, but there is no guarantee of the order in which they will be executed. The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TimeoutAttribute> isn't supported on methods with the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.GlobalTestInitializeAttribute>. | |
| > Multiple methods with these attributes in the assembly are allowed, but there's no guarantee of the order in which they'll execute. The <xref:Microsoft.VisualStudio.TestTools.UnitTesting.TimeoutAttribute> isn't supported on methods with the <xref:Microsoft.VisualStudio.TestTools.UnitTesting.GlobalTestInitializeAttribute>. |
|
|
||
| #### `TimeoutAttribute` | ||
|
|
||
| The [Timeout](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TimeoutAttribute) attribute can be used to specify the maximum time in milliseconds that a test method is allowed to run. If the test method runs longer than the specified time, the test will be aborted and marked as failed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| The [Timeout](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TimeoutAttribute) attribute can be used to specify the maximum time in milliseconds that a test method is allowed to run. If the test method runs longer than the specified time, the test will be aborted and marked as failed. | |
| The [Timeout](xref:Microsoft.VisualStudio.TestTools.UnitTesting.TimeoutAttribute) attribute can be used to specify the maximum time in milliseconds that a test method is allowed to run. If the test method runs longer than the specified time, the test is aborted and marked as failed. |
| This attribute can be applied to any test method or any fixture method (initialization and cleanup methods). It is also possible to specify the timeout globally for either all test methods or all test fixture methods by using the [timeout properties of the runsettings file](./unit-testing-mstest-configure.md#mstest-element). | ||
|
|
||
| > [!NOTE] | ||
| > The timeout is not guaranteed to be precise. The test will be aborted after the specified time has passed, but it might take longer before the step is cancelled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| > The timeout is not guaranteed to be precise. The test will be aborted after the specified time has passed, but it might take longer before the step is cancelled. | |
| > The timeout isn't guaranteed to be precise. The test is be aborted after the specified time passes, but it might take longer before the step is cancelled. |
cc @Youssef1313
Internal previews