xunit Assert.NotNull() 不能很好地处理 C# 可空类型
Assert.NotNull(res);
Assert.Equal(1, res.Foo); // CS8602 warning here
我正在使用 xunit.assert 2.4.1、.NET 6.0、VS 2022。
当“Ctrl+Click”导航到 Assert.NotNull() 源代码 我可以看到它的定义是
public static void NotNull(object @object)
我实际上期望看到的
public static void NotNull([NotNull] object? @object)
从 xunit 源代码中可以看到,仅当 时才使用可空风格的方法XUNIT_NULLABLE
条件编译变量已启用。难道 nuget 下载了 xunit.assert 包的“不可为空”版本吗?我们如何强制使用“可空”版本(使用定义的 XUNIT_NULLABLE 构建)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最后,Xunit 2.4.2已发布,并且essert.notnull()与C#无效类型效果很好!
以下代码是实现。
Finally, xunit 2.4.2 has been released and Assert.NotNull() plays nicely with C# nullable types!!
The following code is the implementation of
NotNull
method in xunit.assert 2.4.2.