Skip to content

Mock test builds emit nullable-reference and assertion-style warnings #7828

Closed

Description

@thomhurst

Summary

Building the mock test project emits nullable-reference and assertion-style warnings from existing test sources. These warnings make new diagnostics harder to spot during validation. The tests should express their intended nullability and assertions without those warnings.

Reproduction

Using .NET SDK 11.0.100 on Windows, run:

dotnet build tests/TUnit.Mocks.Tests/TUnit.Mocks.Tests.csproj --framework net11.0 --target:Rebuild

The affected sources are present on main at d4c0670f412a07caea6652f810c5c81a4571b339. The warnings were observed when compiling the project for both net10.0 and net11.0 while validating #7820.

Expected and actual

Expected: test assertions and nullable values compile without nullable-reference or assertion-style warnings.

Actual examples:

  • CS8602 in AsyncTests.cs:428 and :442, and in MockAssertionExtensionsTests.cs:54,78,92,116 when dereferencing an exception returned by Assert.ThrowsAsync.
  • CS8620 in KitchenSinkConcreteTests.cs:491,497, KitchenSinkAbstractTests.cs:517,523, and RealWorldScenarioTests.cs:574,576 for nullable mock argument matchers.
  • CS8631 in StringAndTypeMatcherTests.cs:114 for collection element nullability.
  • TUnitAssertions0005 in existing tests, including PerformanceOptimizationTests.cs:308, and TUnitAssertions0014 in OutRefAssignmentTests.cs:44.

The .NET 11 build log contains 17 CS8602, six CS8620, one CS8631, 91 TUnitAssertions0005, and one TUnitAssertions0014 diagnostics. Some assertions deliberately exercise assertion or verification behavior, so preserve that behavior when correcting them. Intentional interface hiding and type-parameter-shadowing fixtures are outside this request.

Environment

.NET SDK 11.0.100; Windows x64; targets net10.0 and net11.0. Existing analyzer-project and dependency restore warnings are tracked separately in #7410 and #7412.

Please correct these test-source warnings while preserving the tests' intended behavior.

Activity

  1. added
    bugSomething isn't working
    P3Low: cleanup, minor enhancement, or rare edge case
    on Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low: cleanup, minor enhancement, or rare edge casebugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions