Table of Contents

Analyzers 1.12.0 2024 April 11

Today, we're shipping three new releases:

  • xUnit.net Core Framework v2 2.7.1 (release notes)
  • xUnit.net Analyzers 1.12.0
  • xUnit.net Visual Studio adapter 2.5.8 (release notes)

It's been 2 months since the release of 1.11.0.

As always, we'd like to thank all the users who contributed to the success of xUnit.net through usage, feedback, and code. 🎉

Release Notes

These release notes are a comprehensive list of changes from 1.11.0 to 1.12.0.

General

  • We are considering when it's appropriate to remove support for Visual Studio 2019 from the analyzers, as this version of Visual Studio has now left mainstream support. Based on a poll done on Mastodon there still appears to be a small percentage of users who are using VS 2019, so we have delayed the removal for the time being and will reconsider it again later. The next scheduled removal will be support for VS 2022 17.4 on or after July 11th, when it officially goes out of support. VS 2022 17.6+ will still be supported at that time.

Usage Analyzers

  • We have added xUnit1044 and xUnit1045 to highlight when you use data types in TheoryData<> that are not (1044) or might not (1045) be serializable. The purpose is to highlight cases where you may not be able to run individual data rows in Test Explorer in Visual Studio because of the non-serializability of the theory data. These are separate rules so that you can choose to disable the "might not" rule (which catches a wider net of types) without losing access to the "does not" rule (which only triggers for types known to never be serializable). xunit/xunit#2866

  • We have added xUnit1046 and xUnit1047 to highlight when you pass data to the constructor of TheoryDataRow in xUnit.net v3 that is not (1046) or might not (1047) be serializable. The purpose is to highlight cases where you may not be able to run individual data rows in Test Explorer in Visual Studio because of the non-serializability of the theory data. These are separate rules so that you can choose to disable the "might not" rule (which catches a wider net of types) without losing access to the "is not" rule (which only triggers for types known to never be serializable). Note that we usually have better type information here, since we're using the actual data in question (which the compiler may know more about) vs. the two rules above, which are relying on the generic types rather than concrete data.

  • BUG: We fixed an issue in xUnit1013 that was incorrectly triggering for overridden test methods which did not include [Fact] or [Theory] because the base method already included the correct attribute (and that attribute is inherited from the base test method). This only affected analysis, as the test was running correctly at runtime. xunit/xunit#2911

Suppressors

This is a new category! We've added our first two suppressors in this release.

  • The first is a suppressor for CA1515 ("Consider making public types internal"). This is coming in .NET 9 and can be seen already showing up when you are using early access builds. Since all test classes in xUnit.net projects are considered "unreferenced", this analyzer is incorrectly suggesting that the types be made internal. We now suppress this for any class which has at least one test method in it. This includes not only [Fact] and [Theory] but also any attributes derived from FactAttribute from third party test framework extensions. xunit/xunit.analyzers#182

  • We have added a suppressor for CA2007 ("Do not directly await a Task"). This is the analyzer that recommends users always add .ConfigureAwait(false) to task code, which is incorrect behavior for xUnit.net tests since this will push the unit test off of the thread pool which we use to limit concurrency. Note that this only applies to code directly in unit test methods; code outside of unit tests (including code in private functions or lambdas inside of a test method) will still raise CA2007 if you have it enabled, as usage there does not break xUnit.net's parallelization limitation functionality.