Search code examples
unit-testingasync-awaitnunitvs-unit-testing-framework

Can't overload async/await methods with NUnit Test Adapter


I'm getting a System.Reflection.AmbiguousMatchException when at least one of the methods are async and the method names match when the NUnit tests are run using the NUnit Test Adapter 2.0.0.0 in Visual Studio. I'm able to run the tests without problem when I use the ReSharper unit test runner and when I use the NUnit GUI test runner (NUnit-2.6.4.msi). Is this a bug in the NUnit Test Adapter?

[TestFixture]
public class SimpleRepro
{
    [Test]
    [TestCase("I'm valid")]
    [TestCase("So am I!")]
    public async Task Foo(string resource)
    {
        Assert.IsNotNull(resource);

        await Task.Delay(new TimeSpan(0, 0, 1));
    }

    [Test]
    public async Task Foo()
    {
        Assert.IsNotNull(Guid.NewGuid().ToString("N"));

        await Task.Delay(new TimeSpan(0, 0, 1));
    }
}

I've cross posted this on the GitHub issues list.


Solution

  • This was confirmed as a bug by one of the library owners. According to their comment it looks like this will be addressed in a future release:

    Since it only occurs in the adapter, it should be something we can fix!

    This is great news of course. In the mean time you can work around this issue by not overloading async/await methods in your unit tests.