Hello,
I am unit testing asynchronous methods and get the following messages for my unit test method:
CRR0034 The 'TestMethod' async method should contain the 'Async' suffix
CRR0035 The async method 'TestMethod' should contain CancellationToken parameter
CRR0035 should not be reported, since it is not possible to pass a CancellationToken parameter to a unit test method (at least in MSTest).
I am not too sure about CRR0034, but I do not think it makes sense to add the Async suffix to a unit test method. The suffix is to inform callers that this method is intended to be used asynchronously, but for unit tests, the method will be executed by the IDE/Tool. It also would clutter the method name, that is usually used to transport the meaning of the test and the expected outcome.
I attached a sample project, but here are the method and test method for convenience:
C#public static async Task<string> GetFooAsync(CancellationToken cancellationToken = default)
{
await Task.Delay(1000, cancellationToken).ConfigureAwait(false);
return "Foobar";
}
C#[TestMethod]
public async Task TestMethod()
{
string result = await Foobar.GetFooAsync().ConfigureAwait(false);
Assert.AreEqual("Foobar", result);
}
Hi,
We agree that these diagnostics should not be shown for test methods. We will fix this issue in future builds.