Calls to methods which accept CancellationToken should use TestContext.Current.CancellationToken
A violation of this rule occurs when a method that accepts CancellationToken
is not passed a cancellation token.
To provide for orderly cancellation (especially for tests which have timed out), developers should pass a cancellation
token to any method which accepts one. The cancellation token should be TestContext.Current.CancellationToken
or a
linked token source that includes it.
To fix a violation of this rule, pass TestContext.Current.CancellationToken
.
using System.Threading.Tasks;
using Xunit;
public class xUnit1051
{
[Fact]
public async ValueTask TestMethod()
{
await Task.Delay(1);
}
}
using System.Threading.Tasks;
using Xunit;
public class xUnit1051
{
[Fact]
public async ValueTask TestMethod()
{
await Task.Delay(1, TestContext.Current.CancellationToken);
}
}