Assert.IsNotNull does not specify that the value parameter will never be null if the method returns. This used to work in version 2.x.x. Is there a reason for this? It seems that the object? value parameter needs to be annotated with the [NotNullAttribute]. The attribute is there in 2.2.10, but in 3.0.0 it's missing.
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Example;
[TestClass]
public class Tests
{
[TestMethod]
public void Test1()
{
string? test = MethodToTest();
Assert.IsNotNull(test);
Assert.AreEqual(3, test.Length); // CS8602: Dereference of a possibly null reference.
string? MethodToTest()
{
return null; // Or anything else
}
}
}
Expected behavior
No warnings.
Actual behavior
The code emits diagnostic CS8602 while it is perfectly valid. test cannot be null because Assert.IsNotNull will throw if it is.
Describe the bug
Assert.IsNotNull
does not specify that thevalue
parameter will never be null if the method returns. This used to work in version 2.x.x. Is there a reason for this? It seems that theobject? value
parameter needs to be annotated with the[NotNullAttribute]
. The attribute is there in 2.2.10, but in 3.0.0 it's missing.Steps To Reproduce
Expected behavior
No warnings.
Actual behavior
The code emits diagnostic CS8602 while it is perfectly valid.
test
cannot be null becauseAssert.IsNotNull
will throw if it is.