1

我编写了一堆使用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 不支持参数化测试12

4

1 回答 1

2

经过进一步的调试和测试,我得出的结论是 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);
    }
}

该问题似乎仅存在于具有重载方法的测试中,其中至少一个重载使用 async/await


1:根据此信息编辑我的问题会将其变成变色龙问题,并且不鼓励通过自我回答的变色龙,因此我也取消了该选项。

于 2015-11-05T18:11:25.060 回答