代码检查:NUnit。 测试方法声明中缺少 'CancelAfter' 特性.
此检查会报告那些声明了末尾 CancellationToken 参数,但在方法或其包含的测试固定例程上没有 [CancelAfter(...)] 特性的 NUnit 4 测试方法。
没有 CancelAfter 时,NUnit 不会自动提供取消令牌。 检查会高亮显示 CancellationToken 参数,以表明测试签名可能缺少超时特性。
示例
using System.Threading;
using NUnit.Framework;
public class Tests
{
[Test]
public void Should_cancel(CancellationToken ct)
{
}
}
using System.Threading;
using NUnit.Framework;
public class Tests
{
[Test]
[CancelAfter(1000)]
public void Should_cancel(CancellationToken ct)
{
}
}
快速修复
快速修复会将 [CancelAfter(1000)] 添加到测试方法,并允许调整超时值。
2026年 5月 8日