NUnit CLI/C++ 测试用例:不能使用数组作为参数

问题描述

我正在尝试使用数组作为参数在 C++/CLI 中创建 NUnit 测试用例。示例:

[NUnit::Framework::TestCase(gcnew array<int>{255,128})]
void MyTestWithAnArray(array<int>^ myArray)
{
    NUnit::Framework::Assert::IsNotEmpty(myArray);
}

这编译得很好,但是在运行测试时我得到了这个运行时异常:

System.Reflection.CustomAttributeFormatException: Binary format of the specified custom attribute was invalid.
    at System.Reflection.CustomAttribute._CreateCaObject(RuntimeModule pModule,IRuntimeMethodInfo pCtor,Byte** ppBlob,Byte* pEndBlob,Int32* pcNamedArgs)
    at System.Reflection.CustomAttribute.CreateCaObject(RuntimeModule module,IRuntimeMethodInfo ctor,IntPtr& blob,IntPtr blobEnd,Int32& namedArgs)
    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeModule decoratedModule,Int32 decoratedMetadataToken,Int32 pcaCount,RuntimeType attributeFilterType,Boolean mustBeInheritable,IList derivedAttributes,Boolean isDecoratedTargetSecurityTransparent)
    at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeMethodInfo method,RuntimeType caType,Boolean inherit)
    at NUnit.Framework.Internal.MethodWrapper.GetCustomAttributes[T](Boolean inherit)
    at NUnit.Framework.Internal.Builders.DefaultTestCaseBuilder.BuildFrom(IMethodInfo method,Test parentSuite)
    at NUnit.Framework.Internal.Builders.NUnitTestFixtureBuilder.AddTestCasesToFixture(TestFixture fixture)
    at NUnit.Framework.Internal.Builders.NUnitTestFixtureBuilder.BuildFrom(ITypeInfo typeInfo,ITestFixtureData testFixtureData)
    at NUnit.Framework.TestFixtureAttribute.<BuildFrom>d__48.MoveNext()
    at NUnit.Framework.Internal.Builders.DefaultSuiteBuilder.BuildFrom(ITypeInfo typeInfo)

在 C# 中创建相同的测试没有任何问题:

[TestCase(new int[] {255,128})]
public void MyArrayTest(int[] myArray)
{
    Assert.IsNotEmpty(myArray);
}

有人知道我可能做错了什么吗? 使用的 NUnit 版本是 3.8.1

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...