Skip to content

Recognize that Assert.ThrowsAsync etc now return a Task that needs awaiting. #988

Closed

Description

@manfred-brands

In NUnit 5, the Async named method are actually converted to async and now return a Task

This rule is to ensure that users await the task instead of ignoring it meaning the code isn't actually executed.

        [Test]
        public void GenericThrowsAsyncSucceedsWithDelegate()
        {
            Assert.ThrowsAsync<ArgumentException>(AsyncTestDelegates.ThrowsArgumentException);
        }

The analyzer should detect this and offer a code fix to not only await the method but also potentially change the return type to async Task:

        [Test]
        public async Task GenericThrowsAsyncSucceedsWithDelegate()
        {
            await Assert.ThrowsAsync<ArgumentException>(AsyncTestDelegates.ThrowsArgumentException);
        }

Activity

  1. added this to the Release 4.14 milestone on Jun 1, 2026
  2. changed the title [-]Recognize that Assert.ThrowAsync etc now return a Task that needs awaiting.[/-] [+]Recognize that Assert.ThrowsAsync etc now return a Task that needs awaiting.[/+] on Jun 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions