Assert.NotNull(res);
Assert.Equal(1, res.Foo); // CS8602 warning here
I'm using xunit.assert 2.4.1, .NET 6.0, VS 2022.
When "Ctrl+Click" navigating to the Assert.NotNull() source code I can see it defined as
public static void NotNull(object @object)
while I was actually expecting to see
public static void NotNull([NotNull] object? @object)
From the xunit source code one can see that nullable flavour of methods are used only when XUNIT_NULLABLE
conditional compilation variable is enabled. Can it be that nuget downloaded "non-nullable" version of the xunit.assert package? How can we force a "nullable" version (built with the XUNIT_NULLABLE
defined)?
Assert.NotNull()
does not prevent the compiler from telling the warning. You can create a custom NotNull() methodprivate void NotNull([NotNull] object? @object) {}
and use it to silence the compiler, so why cannot NUnitAssert.NotNull()
do the same? And actually it can, please follow the link I've shared in the question and maybe you'll get my question.