BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News MSTest 3.4 Release: Improved Analyzers, WinUI, Playwright and Aspire Support Added

MSTest 3.4 Release: Improved Analyzers, WinUI, Playwright and Aspire Support Added

Microsoft released a new version of MSTest, a testing framework for .NET. Version 3.4 introduces a couple of improvements, bug fixes, and new features. Key updates include improvements to MSTest.Analyzers, MSTest.Sdk, and MSTest.Runner, along with added support for WinUI applications.

As stated by the development team, these updates address long-standing user-reported issues. Other changes include the addition of [Timeout] support to all fixture methods and STA thread support for UI tests. Additionally, the testing process with Playwright and Aspire has been simplified by removing the project boilerplate.

The MSTest.Analyzers now include nine new rules to promote best practices and avoid common pitfalls. These rules ensure proper usage of attributes and assertions, enforce design preferences and enhance code readability and maintainability.

For instance, MSTEST0017 mandates correct order for assertion arguments, while MSTEST0019 and MSTEST0020 guide on using TestInitialize methods and constructors for initialisation tasks.

Other rules focus on proper cleanup methods, avoiding boolean assertion negation, and appropriate usage of TestContext. Readers can explore the official Microsoft documentation to learn more about all the rules available.

Enhancements to MSTest also include long-requested support for STA threads in VSTest and MSTest.Runner, facilitating UI element testing across supported target frameworks. STA thread support can be enabled by setting <ExecutionThreadApartmentState>STA</ExecutionThreadApartmentState> in the runsettings file.

The official blog post reveals the plans to refine this feature in future by allowing specific tests or test classes to run in STA thread mode, with ongoing community feedback on the GitHub repository.

As mentioned previously, the release introduces the ability to define timeouts on fixture methods such as AssemblyInitialize, AssemblyCleanup, ClassInitialize, ClassCleanup, TestInitialize, and TestCleanup. As stated by the development team, this feature gives developers more control over the execution of tests.

([ClassCleanup] will time out after 1 second, Source: Microsoft DevBlogs)

Furthermore, the MSTest.Sdk has been updated to include global usage of the MSTest namespace, with the motivation to simplify the test writing process. With this version, users no longer need to add using Microsoft.VisualStudio.TestTools.UnitTesting in their files.

With a note that this change respects user preferences for implicit usings., the developers can take a look at the updated sample project for further exploration and demos.

The project setup has been simplified for Playwright and Aspire. Developers can now enable Playwright testing by adding <EnablePlaywright>true</EnablePlaywright> to their project and also for the .NET Aspire testing, developers can enable it by adding <EnableAspireTesting>true</EnableAspireTesting> this section into their settings.

Lastly, responding to community feedback and requests, the MSTest.Runner now supports WinUI tests.

The development team stated the following:

Check out our project sample and we are working to simplify testing un-packaged applications. We have also enhanced the runner's performance by using the built-in System.Text.Json for .NET instead of Jsonite and by caching command line options.

Readers interested in more project details and updates can explore the official GitHub repository.

About the Author

Rate this Article

Adoption
Style

BT