Uploaded image for project: 'Rules Repository'
  1. Rules Repository
  2. RSPEC-3430

Test methods should not be "async void"

    XMLWordPrintable

    Details

    • Type: Code Smell Detection
    • Status: Closed
    • Resolution: Duplicate
    • Labels:
    • Message:
      Remove "async" from this method or change its return type.
    • Highlighting:
      Hide

      Primary: async void
      Secondary: test attribute

      Show
      Primary: async void Secondary: test attribute
    • Default Severity:
      Blocker
    • Impact:
      High
    • Likelihood:
      High
    • Default Quality Profiles:
      Sonar way
    • Targeted languages:
      C#
    • Remediation Function:
      Constant/Issue
    • Constant Cost:
      15min

      Description

      In general, async void test methods are not executed by test frameworks, therefore it's better to avoid them altogether.

      Noncompliant Code Example

          [TestMethod]
          public async void MyIgnoredTestMethod()  // Noncompliant
          { /* ... */ }
      

        Attachments

          Activity

            People

            Assignee:
            Unassigned Unassigned
            Reporter:
            ann.campbell.2 Ann Campbell
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: