Table of Contents

Analyzers 2.0.0 2026 August 14

Today, we're shipping three new releases:

  • xUnit.net Core Framework v3 4.0.0 (release notes)
  • xUnit.net Analyzers 2.0.0
  • xUnit.net Visual Studio adapter 4.0.0 (release notes)

Hello, 2.0!

The last major release (1.0.0) was 4 years ago, and the last minor release (1.27.0) was 7 months ago. This new release adds support for analyzing v3 Native AOT projects. The analyzer index and individual analyzer documentation pages for the analyzers have been updated to include flags to indicate when the analyzer applies to Native AOT projects.

This new release includes:

  • 16 new usage analyzers
  • 1 new assertion analyzer
  • 3 new extensibility analyzers
  • Several updates and bug fixes

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

Note

This release removes support for Visual Studio 2019. Our new minimum supported version of Roslyn is 4.11, which will support Visual Studio 2022 17.11 (and later) as well as .NET SDK 8.0.400 (and later), both released in August 2024. Earlier versions of Visual Studio or .NET SDK will not be supported.

Release Notes

These release notes are a comprehensive list of changes from 1.27.0 to 2.0.0.

General

  • With the update to Roslyn 4.11, we have found all instances of array usage analysis, and updated them to support collection expressions as well (e.g., using the literal collection syntax [1, 2, 3] in addition to syntaxes like new[] { 1, 2, 3 }).

Usage Analyzers

  • We have updated xUnit1007 to stop triggering when the [ClassData] source implements either IEnumerable or IEnumerable<object>. Although these signatures are not ideal, they do permit returning data that otherwise implements one of the required contracts (object[] for v2 and v3, as well as ITheoryDataRow and ITuple for v3). xunit/xunit#3507

  • We have disabled xUnit1008 in Native AOT, since there is no singular definition for what a test method is defined as when using xUnit.net extensions (like custom Theory-style attributes).

  • We have updated xUnit1010 to stop reporting string values which are correctly converted at runtime to their target numeric type (for example, "123" passed for an int). xunit/xunit#2354

  • We have updated xUnit1019 to stop triggering when the [MemberData] source implements either IEnumerable or IEnumerable<object>. Although these signatures are not ideal, they do permit returning data that otherwise implements one of the required contracts (object[] for v2 and v3, as well as ITheoryDataRow and ITuple for v3). xunit/xunit#3508

  • We have updated xUnit1025 to report duplicate inline data where the values are the same but come from different types (for example, 1 as an int vs. 1 as a long). xunit/xunit#2957

  • We have updated xUnit1045 to include some deeper analysis of the actual values being provided, so that this analyzer can reduce it instances of false positives relating to potentially serializability of values. xunit/xunit#2981

  • We have added xUnit1054 ("Properties used for conditional skipping must be public, static, and return bool"). This diagnostic is raised when either SkipUnless or SkipWhen properties don't point to an appropriate property.

  • We have added xUnit1055 ("Conditional skipping cannot set both SkipUnless and SkipWhen"). This diagnostic is raised when both SkipUnless and SkipWhen are set.

  • We have added xUnit1056 ("Type must have a single public non-static constructor"). This diagnostic is raised when a given type is required to have a single public constructor. This includes test classes and test fixtures.

  • We have added xUnit1057 ("Type must be public or internal"). This diagnostic is raised when a given type must have either public or internal visibility so that the Native AOT source generators can reference the type. This is only raised in Native AOT mode, and does not affect reflection mode.

  • We have added xUnit1058 ("Generic collection definitions are not supported in Native AOT"). This diagnostic is raised when a collection definition class is defined as a generic class. Closing open generics is not available in Native AOT.

  • We have added xUnit1059 ("Test classes may not be decorated with ICollectionFixture<>"). This diagnostic is raised when a test class was decorated with ICollectionFixture, as test classes cannot specify collection fixtures (only collection definitions can).

  • We have added xUnit1060 ("Cultured test methods must have at least one culture"). This diagnostic is raised when a cultured tests (using CulturedFact or CulturedTheory) specifies zero cultures, which would result in zero tests.

  • We have added xUnit1061 ("Fact methods cannot be generic"). This diagnostic is raised when a test method decorated with [Fact] or [CulturedFact] is an open generic. Since there is no data around which to close the open generic, this is not legal.

  • We have added xUnit1062 ("Theory methods cannot be generic in Native AOT"). This diagnostic is raised when a test method decorated with [Theory] or [CulturedTheory] is an open generic. Closing open generics is not available in Native AOT.

  • We have added xUnit1063 ("Test class cannot be an open generic type"). This diagnostic is raised when a test class is an open generic type. Since there is no data around which to close the open generic, this is not legal.

  • We have added xUnit1064 ("Theory parameter cannot use params modifier in Native AOT"). This diagnostic is raised when a test method parameter is marked with the params modifier. Support for params parameters is not available in Native AOT.

  • We have added xUnit1065 ("MemberData member may not be overloaded in Native AOT"). This diagnostic is raised when [MemberData] points to an overloaded method in Native AOT mode. Support for resolving the method ambiguity is not available in Native AOT mode.

  • We have added xUnit1066 ("MemberData parameter cannot use params modifier in Native AOT"). This diagnostic is raised when a method referenced by [MemberData] has a parameter with the params modifier. Support for params parameters is not available in Native AOT.

  • We have added xUnit1067 ("There is no matching MemberData method argument"). This diagnostic is raised when the [MemberData] attribute does not provide enough arguments for the method.

  • We have added xUnit1068 ("MemberData cannot point to an open generic type"). This diagnostic is raised in Native AOT-mode when [MemberData] is pointing to a type which an open generic. Open generics cannot be closed at runtime in Native AOT. xunit/xunit#3556

  • We have added xUnit1069 ("Test methods with a Timeout should reference TestContext.Current.CancellationToken"). This diagnostic is raised when a test with Timeout set does not have any references to TestContext.Current.CancellationToken. Usage of the context cancellation token is key to causing tests to terminate as quickly as possible after they've timed out. xunit/xunit#2977

  • BUG: We have fixed an issue with xUnit1008 where it would inappropriate trigger for attributes which implemented IFactAttribute or ITheoryAttribute. xunit/xunit#3518

  • BUG: We have fixed an issue with xUnit1010 where it was improperly skipping invalid attribute parameters, causing it to potentially report incorrect issues for later parameters (even when they were correct). xunit/xunit#3569

Assertion Analyzers

  • We have added xUnit2033 ("Use the assertion return value instead of re-deriving it"). This diagnostic is raised when test code is failing to take advantage of assertions which return values (like Assert.Single and Assert.IsType).

  • BUG: We have fixed an issue with xUnit2006 where it was not accounting for the fact that Assert.StrictEqual has a different signature in Native AOT.

  • BUG: We have fixed an issue with the fixer for xUnit2023 which was incorrectly duplicating comments and/or not correctly formatting the resulting changed code. xunit/xunit#3336

Extensibility Analyzers

  • We have added xUnit3004 ("Type does not implement interface"). This diagnostic is raised when the analyzer determines that a given type needs to implement an interface that it does not. The interfaces currently supported here are:

    • ICodeGenTestCollectionFactory (for CollectionBehaviorAttribute in Native AOT mode)
    • IConsoleResultWriter (for RegisterConsoleResultWriterAttribute and RegisterResultWriterAttribute)
    • IMicrosoftTestingPlatformResultWriter (for RegisterMicrosoftTestingPlatformResultWriterAttribute and RegisterResultWriterAttribute)
    • IRunnerReporter (for RegisterRunnerReporterAttribute)
    • ITestCaseOrderer (for test case orderers)
    • ITestClassOrderer (for test class orderers)
    • ITestCollectionOrderer (for test collection orderers)
    • ITestFramework (for TestFrameworkAttribute)
    • ITestMethodOrderer (for test method orderers)
    • ITestPipelineStartup (for TestPipelineStartupAttribute)
    • IXunitSerializer (for RegisterXunitSerializerAttribute)
    • IXunitTestCollectionFactory (for CollectionBehaviorAttribute in reflection mode)
  • We have added xUnit3005 ("Type must have an appropriate non-obsolete public constructor"). This diagnostic is raised when an appropriate constructor cannot be found for the given extensibility type; the constructor must be public, non-static, and non-[Obsolete]. Those types include:

    • Assembly fixtures (no parameters)
    • ICodeGenTestCollectionFactory implementations (single parameter ICodeGenTestAssembly testAssembly)
    • IConsoleResultWriter implementations (no parameters)
    • IMicrosoftTestingPlatformResultWriter implementations (no parameters)
    • IRunnerReporter implementations (no parameters)
    • ITestCaseOrderer implementations (no parameters)
    • ITestClassOrderer implementations (no parameters)
    • ITestCollectionOrderer implementations (no parameters)
    • ITestFramework (single parameter string? configFileName, or no parameters)
    • ITestMethodOrderer implementations (no parameters)
    • ITestPipelineStartup implementations (no parameters)
    • IXunitSerializer implementations (no parameters)
    • IXunitTestCollectionFactory implementations (single parameter IXunitTestAssembly testAssembly)
  • We have added xUnit3006 ("Test case implementation must be serializable") and xUnit3007 ("Test case implementation might not be serializable"). These diagnostics are raised in reflection-mode when test case implementations are definitely not serializable (3006) or might not serializable (3007). To resolve this, a test case must either implement IXunitSerializable or be supported by a registered external implementation of IXunitSerializer. xunit/xunit#3535