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

徘徊边缘 提交于 2019-12-11 11:59:56

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/33620614/cant-overload-async-await-methods-with-nunit-test-adapter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!