NUnit TestCaseAttribute 导致 AmbiguousMatchException 与 NUnit VS 适配器
NUnit TestCaseAttribute causing AmbiguousMatchException with NUnit VS Adapter
我写了一堆利用 TestCaseAttribute 的单元测试。当我使用 ReSharper 单元测试 运行ner 时,这些测试 运行 在我的本地机器上非常棒。不幸的是,当我使用 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 在线托管构建服务器进行构建,并且 依赖测试适配器来 运行 我们的 NUnit 单元测试 。这意味着我需要想出一种方法来使它与属性一起工作(更喜欢),否则我必须解决这个限制。
我是否必须放弃使用 TestCaseAttribute,因为 MSTest 不支持参数化测试1,2?
经过进一步调试和测试我得出结论,TestCaseAttribute 不是问题的原因。我是在回答我自己的问题,而不是删除 1 以防其他人落入与我相同的陷阱。
正如您在以下测试中所见,TestCaseAttribute 工作正常。这些测试 运行 通过 VS 测试适配器和 ReSharper 测试非常好 运行ner。
[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);
}
}
这个问题似乎只存在于 .
的测试中
1:不鼓励根据此信息编辑我的问题会将其变成 chameleon question, and a chameleon via self answer,因此我也拒绝了该选项。
我写了一堆利用 TestCaseAttribute 的单元测试。当我使用 ReSharper 单元测试 运行ner 时,这些测试 运行 在我的本地机器上非常棒。不幸的是,当我使用 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 在线托管构建服务器进行构建,并且 依赖测试适配器来 运行 我们的 NUnit 单元测试 。这意味着我需要想出一种方法来使它与属性一起工作(更喜欢),否则我必须解决这个限制。
我是否必须放弃使用 TestCaseAttribute,因为 MSTest 不支持参数化测试1,2?
经过进一步调试和测试我得出结论,TestCaseAttribute 不是问题的原因。我是在回答我自己的问题,而不是删除 1 以防其他人落入与我相同的陷阱。
正如您在以下测试中所见,TestCaseAttribute 工作正常。这些测试 运行 通过 VS 测试适配器和 ReSharper 测试非常好 运行ner。
[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);
}
}
这个问题似乎只存在于
1:不鼓励根据此信息编辑我的问题会将其变成 chameleon question, and a chameleon via self answer,因此我也拒绝了该选项。