-
Notifications
You must be signed in to change notification settings - Fork 6.1k
Create unit-testing-mstest-migration-from-v1-to-v3.md #43354
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
Merged
Merged
Changes from 14 commits
Commits
Show all changes
95 commits
Select commit
Hold shift + click to select a range
76e9836
Create unit-testing-mstest-migration-from-v1-to-v3.md.md
engyebrahim 412dcf7
Rename unit-testing-mstest-migration-from-v1-to-v3.md.md to unit-test…
engyebrahim 223acf1
Update toc.yml
engyebrahim 109ddd6
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim b4d7056
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 5d3ce9b
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim d55d262
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim f3d2dbb
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim d4532fe
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim ecaedba
Update toc.yml
engyebrahim 0fce956
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim d127c17
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim e52d2c4
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 7c2aae9
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim f6c111d
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 4a8b05d
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim b9aefab
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim d929027
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 154aa73
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 250925a
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 832923d
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim d58f8e8
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim b0af89d
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 246cb6b
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 4146acd
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 25191a0
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim ee17725
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 23892dc
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 4b44b63
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 00266c9
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 1d863d4
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 93860a1
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 93547b4
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 99940a1
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 1e894e9
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 7d6d9bb
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 2938c94
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim c138a36
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 474e7ee
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 9ad505e
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 6abbff6
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim fefb548
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim acb6c77
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim f7d4f67
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim c196f57
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim d2f6bed
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 2156cda
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 75083a3
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 3550247
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim e343e48
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim d9ccf05
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim d17b0d7
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 1fac0b5
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 5a66197
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 36b3b5b
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim c9d32ee
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 4d2868e
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim ab49a8e
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 7e13b40
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 6ae6e7e
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 742fabf
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 2bfd015
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim b2c88b3
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 774d60c
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 7fee097
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 0f83f74
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 72e7ed1
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim df2e02c
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 504ea74
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 523a612
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 6db4bad
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 05c3aa5
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 4be47ad
Update docs/navigate/devops-testing/toc.yml
engyebrahim 6d0a818
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 2da2b01
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim c627338
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 3218c7e
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 8f5a035
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 153210f
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 4d8a4e0
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim fdbbd54
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 72e262a
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 39ac5c6
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim fe556ab
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 7adeacc
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 2601ceb
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 745548e
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 1537d92
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 5601126
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 64a4eb7
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 41c588d
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim ba7dcf1
Update docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim cf98bd3
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim abbfd0e
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim 7ca75ab
Update unit-testing-mstest-migration-from-v1-to-v3.md
engyebrahim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
224 changes: 224 additions & 0 deletions
224
docs/core/testing/unit-testing-mstest-migration-from-v1-to-v3.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,224 @@ | ||
| --- | ||
| title: MSTest migration to v3 | ||
| description: Migration guide. | ||
| author: engyebrahim | ||
| ms.author: enjieid | ||
| ms.date: 11/06/2024 | ||
| --- | ||
|
|
||
| # MSTest v3 Migration Guide | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ## Overview | ||
|
|
||
| This guide assists users in upgrading their MSTest projects from v0/v1 to MSTest v3. MSTest v3 introduces new features, improvements, and some breaking changes. | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| --- | ||
|
|
||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ## Introduction and Motivation | ||
|
|
||
| Migrating to MSTest v3 offers several benefits: | ||
|
|
||
| - Improved test execution speeds and memory efficiency. | ||
| - Stricter validation for more reliable tests. | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| - Leveraging modern .NET features and cross-platform compatibility. | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| --- | ||
|
|
||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ## Steps to Migrate | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### 1. Remove Assembly Reference | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Remove the `Microsoft.VisualStudio.QualityTools.UnitTestFramework` reference from your project. | ||
|
|
||
| ```xml | ||
| <Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"> | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <Private>False</Private> | ||
| </Reference> | ||
| ``` | ||
|
|
||
| ### 2. Update Your Project | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - **NuGet Package**: Install the latest [MSTest](https://www.nuget.org/packages/MSTest). | ||
| - **Project File**: Update your project file to use MSTest SDK. | ||
|
|
||
| ```xml | ||
| <Project Sdk="MSTest.Sdk/3.3.1"> | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <PropertyGroup> | ||
| <TargetFramework>net8.0</TargetFramework> | ||
| </PropertyGroup> | ||
| </Project> | ||
| ``` | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### 3. Update Your Code | ||
|
|
||
| - **Replace Deprecated Methods**: Update deprecated methods to newer versions. | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - **Assert.AreEqual/AreNotEqual (with object)** → Use generic versions. | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| **Before** (deprecated): | ||
|
|
||
| ```csharp | ||
| Assert.AreEqual(expectedObject, actualObject); | ||
| Assert.AreNotEqual(expectedObject, actualObject); | ||
| ``` | ||
|
|
||
| **After** (using generics): | ||
|
|
||
| ```csharp | ||
| Assert.AreEqual<object>(expectedObject, actualObject); | ||
| Assert.AreNotEqual<object>(expectedObject, actualObject); | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| - **Assert.AreSame/AreNotSame (with object)** → Use generic versions. | ||
|
|
||
| **Before** (deprecated): | ||
|
|
||
| ```csharp | ||
| Assert.AreSame(expectedObject, actualObject); | ||
| Assert.AreNotSame(expectedObject, actualObject); | ||
| ``` | ||
|
|
||
| **After** (using generics): | ||
|
|
||
| ```csharp | ||
| Assert.AreSame<object>(expectedObject, actualObject); | ||
| Assert.AreNotSame<object>(expectedObject, actualObject); | ||
| ``` | ||
|
|
||
| - **Test Initialization**: Use `TestInitialize` methods for async initialization. | ||
| - **Cleanup**: Use `TestCleanup` methods or the `Dispose` pattern for cleanup. | ||
| - **RunSettings**: The `.testsettings` file is no longer supported, meaning `<LegacySettings>` is also no longer available. Use [.runsettings](https://learn.microsoft.com/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2022) for test configuration. | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| --- | ||
|
|
||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ## New Features in MSTest v3 | ||
|
|
||
| - Improved defaults for test projects | ||
| - Simplified setup and usage | ||
| - Enhanced extensibility of the MSTest runner | ||
| - New Roslyn-based code analyzers for improved test development | ||
| - Support for WinUI applications | ||
| - In-assembly parallel execution | ||
| - Dynamic data sources for data-driven tests | ||
|
|
||
| --- | ||
|
|
||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ## Deprecated Features | ||
|
|
||
| - Dropped support for: | ||
| - **.NET Framework 4.5** (use .NET 4.6.2 or higher) | ||
| - **.NET Standard 1.0** (use .NET Standard 2.0) | ||
| - **UWP versions before 16299** | ||
| - **WinUI versions before 18362** | ||
| - **.NET 5** (use .NET Core 3.1 or .NET 6) | ||
|
|
||
| --- | ||
|
|
||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ## Breaking Changes and Removed APIs | ||
|
|
||
| ### Assertion Overloads | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| MSTest v3 removes certain `Assert` overloads that accept object types to promote type-safe assertions. Update tests using these overloads to specify types explicitly. | ||
|
|
||
| **Example**: | ||
|
|
||
| ```csharp | ||
| // Old (v0/v1) | ||
| Assert.AreEqual(expected, actual); // both are objects | ||
| // New (v3) | ||
| Assert.AreEqual<int>(expectedInt, actualInt); // specify the type | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ``` | ||
|
|
||
| ### DataRowAttribute Updates | ||
|
|
||
| The `DataRowAttribute` constructors have been simplified in MSTest v3. Update parameterized tests using `DataRow` to align with the revised constructors. | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| **Example**: | ||
|
|
||
| ```csharp | ||
| [TestMethod] | ||
| [DataRow(1, "test")] | ||
| public void MyTestMethod(int number, string text) { ... } | ||
| ``` | ||
|
|
||
| ### Timeout Settings | ||
|
|
||
| Timeout settings are standardized across frameworks in MSTest v3. Verify and adjust any timeout configurations in existing tests for compatibility. | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| --- | ||
|
|
||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ## Configuration Changes | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| ### Settings and Configuration Files | ||
|
|
||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| MSTest v3 supports both XML and JSON formats for configuration files. | ||
|
|
||
| 1. **Verify Configurations**: Ensure that existing `.runsettings` files align with MSTest v3’s syntax and structure. | ||
| 2. **Convert to JSON (if applicable)**: For JSON-based configurations, convert XML settings to JSON format. | ||
|
|
||
| --- | ||
|
|
||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| ## Parallel Execution and Performance Optimization | ||
|
|
||
| ### New Parallelism Options | ||
|
|
||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Configure parallel execution in `.runsettings` or JSON configuration files to improve performance. | ||
|
|
||
| **Example**: | ||
|
|
||
| ```json | ||
| { | ||
| "RunConfiguration": { | ||
| "MaxCpuCount": -1 // Uses all available processors | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ### Improved Resource Usage | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| MSTest v3 optimizes resource management, resulting in lower memory usage and better CPU efficiency. | ||
|
|
||
| --- | ||
|
|
||
| ## Handling Obsolete Attributes and Migrating Custom Extensions | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| Review deprecated attributes, such as `[DeploymentItem]`, and replace them with MSTest v3 alternatives where possible. | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| --- | ||
|
|
||
| ## Code Analyzers and Best Practices | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| MSTest v3 includes built-in code analyzers for best practices, avoiding configuration pitfalls, and proper use of MSTest attributes and settings. | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| --- | ||
|
|
||
| ## Sample Code: Migration Example | ||
|
|
||
| ### Before (MSTest v1) | ||
|
|
||
| ```csharp | ||
| [TestMethod] | ||
| [Timeout(1000)] | ||
| [DataRow(1, "data")] | ||
| public void ExampleTestMethod(int number, string data) { | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Assert.AreEqual(number, Convert.ToInt32(data)); | ||
| } | ||
| ``` | ||
|
|
||
| ### After (MSTest v3) | ||
|
|
||
| ```csharp | ||
| [TestMethod] | ||
| [Timeout(1000)] | ||
| [DataRow(1, "data")] | ||
| public void ExampleTestMethod(int number, string data) { | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Assert.AreEqual<int>(number, Convert.ToInt32(data)); | ||
| } | ||
| ``` | ||
|
|
||
| --- | ||
|
|
||
| ## Additional Resources | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| - [New testin platform](https://learn.microsoft.com/dotnet/core/testing/unit-testing-platform-intro?tabs=dotnetcli) | ||
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
engyebrahim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.