如何在C++/CLI NUnit测试中使用ExpectedException?

4

如何做相当于以下内容的操作:

[Test, ExpectedException( typeof(ArgumentOutOfRangeException) )]
void Test_Something_That_Throws_Exception()
{
    throw gcnew ArgumentOutOfRangeException("Some more detail");
}

我想知道如何在C++中使用NUnit(示例中是C#)?据我所见,C++实现的NUnit中没有typeof()函数。

1个回答

7
为了避免其他人花费很长时间寻找,这里提供解决方案:
[Test, ExpectedException( ArgumentOutOfRangeException::typeid )]
void Test_Something_That_Throws_Exception()
{
     throw gcnew ArgumentOutOfRangeException("Some more detail");
}

只需使用异常的::typeid即可 :)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接