Skip to content

NUnit runner fails when test method returns ValueTask<> #3023

Closed
@toolmagic

Description

@toolmagic

Versions:

Nuget packages:
NUnit 3.10.1
NUnit3TestAdapter 3.10.0
System.Threading.Tasks.Extensions 4.5.1

Environment:
Windows 10.1803 17134.286
Visual Studio 2017 15.8.4

Steps to Reproduce:

  1. Create C# Class Library, .NET 4.7.2
  2. Add Nuget references for NUnit, NUnit3TestAdapter and System.Threading.Tasks.Extensions
  3. Add Test Class:
using System.Threading.Tasks;
using NUnit.Framework;

namespace ClassLibrary1
{
    public class Class1
    {
        [Test(/*ExpectedResult = 100*/)]
        public async ValueTask<int> AsyncGetValueTest()
        {
            return await Task.FromResult(100);
        }
    }
}
  1. Run test "AsyncGetValueTest"

Expected Behavior:
NUnit says "Missed ExpectedResult in Test attribute" or "Test methods with return type ValueTask<> are not supported"

Actual Behavior:
NUnit fails with an internal error:
System.NullReferenceException : Object reference not set to an instance of an object.
at NUnit.Framework.Internal.AsyncInvocationRegion.AsyncTaskInvocationRegion.WaitForPendingOperationsToComplete(Object invocationResult)
at C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\AsyncInvocationRegion.cs:line 109
at NUnit.Framework.Internal.Commands.TestMethodCommand.RunAsyncTestMethod(TestExecutionContext context)
at C:\src\nunit\nunit\src\NUnitFramework\framework\Internal\Commands\TestMethodCommand.cs:line 96

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions