Bug Report T836442
Visible to All Users

Code Analysis - False positives of CRR0034 and CRR0035 for test methods

created 5 years ago

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); }
Comments (1)
DevExpress Support Team 5 years ago

    Hi,

    We agree that these diagnostics should not be shown for test methods. We will fix this issue in future builds.

    Answers approved by DevExpress Support

    created 5 years ago

    We have fixed the issue described in this ticket and will include the fix in our next maintenance update. To apply this solution before the official update, request a hotfix by clicking the corresponding link for product versions you require.

    Note: Hotfixes may be unavailable for beta versions and updates that are about to be released.

      Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

      Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.