Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 带有NUnit和AutoData的AutoFixture引发TargetParameterCountException_C#_Unit Testing_Nunit_Autofixture - Fatal编程技术网

C# 带有NUnit和AutoData的AutoFixture引发TargetParameterCountException

C# 带有NUnit和AutoData的AutoFixture引发TargetParameterCountException,c#,unit-testing,nunit,autofixture,C#,Unit Testing,Nunit,Autofixture,在我的单元测试项目中,我安装了AutoFixture(v3.40.0)、NUnit(v2.6.4.)和AutoFixtTrue.NUnit2(v3.39.0)。 我正在其中一个虚拟测试用例上使用AutoData属性 [Test, AutoData] public void IntroductoryTest( int expectedNumber) { } ,但在运行测试时,我得到 System.Reflection.TargetParameterCoun

在我的单元测试项目中,我安装了AutoFixture(v3.40.0)、NUnit(v2.6.4.)和AutoFixtTrue.NUnit2(v3.39.0)。
我正在其中一个虚拟测试用例上使用AutoData属性

[Test, AutoData]
public void IntroductoryTest(
    int expectedNumber)
{               

}
,但在运行测试时,我得到

System.Reflection.TargetParameterCountException : Parameter count mismatch.
   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()
   at NUnit.Core.TestMethod.RunTestCase(TestResult testResult)

有什么我没有安装或缺少的吗?

该异常是由于NUnit没有在运行时加载AutoFixture导致的,因此测试参数没有获得任何参数

原因是它是根据版本编译的,因此,如果要将其与一起使用,则必须将以下内容添加到测试项目的配置文件中:

<configuration>
    <runtime>
        <dependentAssembly>
            <assemblyIdentity
                name="nunit.core.interfaces" 
                publicKeyToken="96d09a1eb7f44a77"
                culture="neutral" />
            <bindingRedirect
                oldVersion="0.0.0.0-2.6.4.14350"
                newVersion="2.6.4.14350" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity
                name="nunit.core"
                publicKeyToken="96d09a1eb7f44a77"
                culture="neutral" />
            <bindingRedirect
                oldVersion="0.0.0.0-2.6.4.14350"
                newVersion="2.6.4.14350" />
          </dependentAssembly>
    </runtime>
</configuration>

,如果测试运行程序使用版本,则需要重定向到:



您需要NUnit和NUnit2吗?这可能会导致这个问题。FWW,NUnice 2的外接程序模型引起了各种各样的问题,因此,如果您有任何选择,请考虑使用Xuni.NET代替。其中AutoFixture.XUnit2和AutoFixture.Xunit已经完美地工作了多年。我刚刚在App.config中添加了
,这就足够了,您可以编辑您的答案,我会将其标记为已接受。该绑定重定向适用于NUnit 2.6.3。在问题中,您提到了NUnit 2.6.4。您使用的是哪个版本?
<configuration>
    <runtime>
        <dependentAssembly>
            <assemblyIdentity
                name="nunit.core.interfaces" 
                publicKeyToken="96d09a1eb7f44a77"
                culture="neutral" />
            <bindingRedirect
                oldVersion="0.0.0.0-2.6.3.13283"
                newVersion="2.6.3.13283" />
          </dependentAssembly>
          <dependentAssembly>
            <assemblyIdentity
                name="nunit.core"
                publicKeyToken="96d09a1eb7f44a77"
                culture="neutral" />
            <bindingRedirect
                oldVersion="0.0.0.0-2.6.3.13283"
                newVersion="2.6.3.13283" />
          </dependentAssembly>
    </runtime>
</configuration>