【问题标题】:NUnit TestCaseAttribute causing AmbiguousMatchException with NUnit VS AdapterNUnit TestCaseAttribute 使用 NUnit VS Adapter 导致 AmbiguousMatchException
【发布时间】:2015-11-05 16:23:58
【问题描述】:

我编写了一堆使用TestCaseAttribute 的单元测试。当我使用 ReSharper 单元测试运行程序时,这些测试在我的本地机器上运行良好。不幸的是,当我使用 NUnit VS Adapter 2.0.0.0 通过 Visual Studio 运行测试时,我得到以下输出:

------ 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) ==========

我们使用 Visual Studio Online 托管的构建服务器进行构建,并且依靠测试适配器来运行我们的 NUnit 单元测试。这意味着我需要找到一种方法来使这个属性与属性一起工作(非常优选),否则我必须解决这个限制。

我是否必须放弃使用 TestCaseAttribute,因为 MSTest 不支持参数化测试1,2?

【问题讨论】:

    标签: unit-testing nunit azure-devops vs-unit-testing-framework parameterized-tests


    【解决方案1】:

    经过进一步调试和测试我得出结论,TestCaseAttribute 不是问题的原因。我正在回答我自己的问题,而不是删除1,以防其他人陷入与我相同的陷阱。

    TestCaseAttribute 可以正常工作,您可以通过以下测试看到。这些测试通过 VS 测试适配器和 ReSharper 测试运行器运行良好。

    [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);
        }
    }
    

    这个问题似乎只存在于具有an overloaded method with at least one of the overloads using async/await 的测试中。


    1:根据此信息编辑我的问题会将其转换为 chameleon question,并且不鼓励使用 chameleon via self answer,因此我也取消了该选项。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-30
      • 1970-01-01
      • 2010-11-25
      相关资源
      最近更新 更多