简体   繁体   English

Nunit组合引发TargetParameterCountException

[英]Nunit Combinatorial throws TargetParameterCountException

I have some test like this: 我有这样的测试:

[Test, Combinatorial]
public void SomeTest(
        [Values(false, true)] bool flag,
        [Values(2, 5)] int someValue))
{
     var entity = new SomeClass();
     entity.Flag = flag;
     entity.SomeValue = someValue;
     var context = entity.GetContext();

     Assert.AreEqual(context.SomeValue, entity.SomeValue);
}

When I try to run test, it throws TargetParameterCountException. 当我尝试运行测试时,它将引发TargetParameterCountException。 StackTrace: 堆栈跟踪:

at System.Reflection.RuntimeMethodInfo.InvokeArgumentsCheck(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
at NUnit.Core.Reflect.InvokeMethod(MethodInfo method, Object fixture, Object[] args)
at NUnit.Core.TestMethod.RunTestMethod(TestResult testResult)
at NUnit.Core.TestMethod.RunTestCase(TestResult testResult)

What is wrong? 怎么了? I use Nunit 3.4.1and VS 2012. Simple tests work well. 我使用Nunit 3.4.1和VS2012。简单的测试效果很好。

Your code is fine and runs fine for me using the NUnit 3 Visual Studio Adapter. 您的代码很好,使用NUnit 3 Visual Studio适配器对我来说运行正常。 Based on the callstack, you are trying to run the code in an older NUnit 2 based adapter. 基于调用堆栈,您尝试在较旧的基于NUnit 2的适配器中运行代码。 It is either an older version of Resharper or an old version of the NUnit Visual Studio Extension from before it was updated to not run NUnit 3 tests. 从更新为不运行NUnit 3测试之前,它要么是Resharper的旧版本,要么是NUnit Visual Studio Extension的旧版本。

Install the NUnit 3 Visual Studio adapter and give that a try. 安装NUnit 3 Visual Studio适配器,然后尝试一下。 If you are using Resharper, you need to pay for an update. 如果您使用的是Resharper,则需要支付更新费用。

Also, pro-tip, you don't need to include the values in the attribute for bool or enums, all values will be automatically injected. 另外,根据提示,您无需在bool或enums属性中包括值,所有值都将自动注入。 You also don't need the Test attribute. 您也不需要Test属性。

Here is my simplified version of your example, 这是我的示例的简化版本,

[Combinatorial]
public void SomeTest([Values] bool flag, [Values(2, 5)] int someValue)
{
    TestContext.WriteLine($"{flag} - ${someValue}");
}

And the results in the Visual Studio Adapter, 然后在Visual Studio适配器中显示结果,

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM