Search code examples
unit-testingnunitazure-devopsvs-unit-testing-frameworkparameterized-tests

NUnit TestCaseAttribute causing AmbiguousMatchException with NUnit VS Adapter


I wrote a bunch of unit tests that utilized the TestCaseAttribute. These tests run great on my local machine when I use the ReSharper unit test runner. Unfortunately, when I run the tests through Visual Studio with the NUnit VS Adapter 2.0.0.0 I get the following output:

------ Run test started ------
NUnit VS Adapter 2.0.0.0 executing tests is started
Loading tests from D:\Projects\Ever\WebApp\Ever.UnitTests\bin\Debug\Ever.UnitTests.dll
Exception System.Reflection.AmbiguousMatchException, 
   Exception thrown executing tests in 
      D:\Projects\Ever\WebApp\Ever.UnitTests\bin\Debug\Ever.UnitTests.dll
NUnit VS Adapter 2.0.0.0 executing tests is finished
========== Run test finished: 0 run (0:00:00.8290488) ==========

We use the Visual Studio Online hosted build server for our build, and that relies on the test adapter to run our NUnit unit tests. This means I need to figure out a way to make this work with the attribute (much preferred) or I have to work around this limitation.

Do I have to abandon the use of the TestCaseAttribute because MSTest doesn't support parameterized tests1,2?


Solution

  • After further debuging and testing I've concluded that the TestCaseAttribute isn't the cause of the issue. I'm answering my own question instead of deleting1 in case anyone else falls into the same trap that I did.

    The TestCaseAttribute works properly as you can see with the following tests. These tests run perfectly well via the VS Test Adapter and the ReSharper test runner.

    [TestFixture]
    public class SimpleReproAttempt
    {
        [Test]
        [TestCase(true, false)]
        [TestCase(false, true)]
        public void DoesNotReproduceIssue(bool a, bool b)
        {
            Assert.IsTrue(a || b);
        }
    
        [Test]
        [TestCase("", false, true)]
        [TestCase(null, true, false)]
        public void DoesNotReproduceIssue(string a, bool b, bool c)
        {
            Assert.IsTrue(b || c);
            Assert.IsNullOrEmpty(a);
        }
    }
    

    The issue seems to be present only in tests that have an overloaded method with at least one of the overloads using async/await.


    1: Editing my question based on this information would turn this into a chameleon question, and a chameleon via self answer is discouraged so I dismissed that option as well.