Back to Xunit

Analyzers 1.2.0

site/releases/analyzers/1.2.0.md

latest8.1 KB
Original Source

Today, we're shipping three new releases:

  • xUnit.net Core Framework v2 2.5.0 (release notes)
  • xUnit.net Analyzers 1.2.0
  • xUnit.net Visual Studio adapter 2.5.0 (release notes)

It's been 7 months since the release of 1.1.0.

This update includes a few new analyzers, lots of updates and bug fixes, and is the first version that officially supports xUnit.net v3 (which is still in alpha). Although we are shipping this with the v2 2.5.0 core framework, as always this remains version independent, and can be used with tests written against any version of the v2 or v3 core framework.

[!IMPORTANT] This version takes a dependency on Roslyn 4.0.1, which means that the only officially supported version of Visual Studio is 2022+, as well as any compatible version of the the C# plugin for Visual Studio Code, .NET SDK, and/or Mono.

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

[!NOTE] We have moved away from Twitter for our occasional updates, and now make those available on our Mastodon account (@[email protected]) and Bluesky account (@xunit.net).

Release Notes

These release notes are a comprehensive list of changes from 1.1.0 to 1.2.0.

Usage Analyzers

  • Updated xUnit1010: This was inadvertently triggering when you passed compatible data that had an explicit conversion operator (for example, passing a string in the data row, and the argument type in the test method supported an explicit conversion from string). This was working at runtime but incorrectly triggering in the analyzer. xunit/xunit#2734{ .issue-link }

  • Updated xUnit1019: xUnit.net v3 now supports returning ITheoryDataRow in addition to object[] to represent a row of data. This new interface allows you to provide additional metadata along with a data row, including a skip message, a custom test display name, a timeout, traits, and a flag which indicates whether the data row should only be run when running explicit tests. The analyzer needed to be updated to not flag on this data type, when used in v3 tests. xunit/xunit#2735{ .issue-link }

  • Updated xUnit1026: We will now ignore unused parameters when the name matches the discard logic specified by IDE0060. That includes parameters named simply _ as well parameters named starting with an underscore followed by a integer number (e.g., _123). xunit/xunit#2730{ .issue-link }

  • Added xUnit1028: Test method must have a valid return type. For v2 tests, that means void or Task, and for v3 tests you can also return ValueTask. Any other return value is invalid. In particular, this should help people who may be accidentally returning ValueTask instead of Task for v2 tests, as v2 does not support ValueTask. xunit/xunit#1415{ .issue-link } xunit/xunit#2733{ .issue-link }

  • Added xUnit1029: Disallow xUnit.net attributes on local functions. Attributes on local functions are relatively new (introduced in C# 9). Adding the xUnit.net test attributes (like [Fact]) is legal in a compiler sense, but we do not discover nor support them. This analyzer should trigger on anything derived from FactAttribute or DataAttribute. xunit/xunit#2277{ .issue-link }

  • BUG: Fixed an issue with xUnit1010 where the analyzer was inadvertently triggering when you passed compatible data that had an explicit conversion operator (for example, passing a string in the data row, and the argument type in the test method supported an explicit conversion from string). This was working at runtime but incorrectly triggering in the analyzer. xunit/xunit#2734{ .issue-link }

  • BUG: Fixed an issue with common code for xUnit1010 and xUnit1012 that was causing an exception in the analyzer when the user was passing an explicit empty array to provide values for a params-style array in the test method. A secondary issue (for non-empty explicit arrays) was also discovered and fixed at the same time. xunit/xunit#2711{ .issue-link }

  • BUG: Fixed a crash in RemoveMethodParameterFix (shared by xUnit1022 and xUnit1026) caused by specifically malformed code in the text editor. xunit/xunit#2675{ .issue-link }

  • BUG: Fixed an issue with xUnit1025 where the analyzer was throwing an exception with specific input data (see the attached bug). xunit/xunit#2662{ .issue-link }

  • BUG: Fixed an issue with xUnit1033 where the fixer ("Generate constructor") generated a constructor that should've been public, but wasn't. xunit/xunit#2721{ .issue-link }

Assertion Analyzers

  • Updated xUnit2013: This analyzer would correctly trigger when using properties like .Count from a concrete collection type (f.e., List<int>) but not from an interface (f.e., ICollection<int>). xunit/xunit#2736{ .issue-link }

  • Updated xUnit2018: We included support for the new Assert.IsNotAssignableFrom assertion. This includes an updated message in the analyzer, and updated code generation for the fixer. xunit/xunit#2727{ .issue-link }

  • Added xUnit2020: When running against v2 2.5+ or v3, you should use Assert.Fail(message) rather than Assert.True(false, message) or Assert.False(true, message). For projects targeting older versions of xUnit.net, this analyzer & fixer does not trigger. xunit/xunit#2521{ .issue-link }

  • BUG: Fixed an issue with xUnit2000 that incorrectly considered new string(' ', 4) to not be a constant expected value in Assert.Equal. xunit/xunit#2394{ .issue-link }

Miscellany

  • The included install.ps1 and uninstall.ps1 files are now the signed versions provided by Microsoft.

  • We have updated to version 4.0.1 of Microsoft.CodeAnalysis. In addition to bringing us up to date with latest language features, this also gives us better coverage when your tests are being compiled with the Nullable Reference Types feature enabled. This should allow us to enable future analyzers based on newer C# language features, and should also help our analyzers be more robust (as the libraries we're consuming now themselves are enabled for Nullable Reference Types).

  • For those who contribute to the source of the analyzers, you'll notice that I did a lot of housekeeping on the source base. New and updated base classes for analyzers and fixers have been standardized across the board, the source has been cleaned up a bit, and most importantly, all fixer tests now require you to pass the fixer key so that only the exact known fixer is applied. This was kinda too loosely specified (optional integer indices), and I wanted to ensure maximum compatibility (and it should also slightly improve performance because the test system knows to only run the singular fixer).

  • Included the README in the NuGet package.