微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决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.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?