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

Jon*_*age 4 testing nunit c++-cli exception expected-exception

你怎么做相当于:

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

...在C++中(有C#的例子)?据我所知,NUnit的C++实现没有typeof()函数.

Jon*_*age 7

为了避免其他人试图寻找它,这里是解决方案:

[Test, ExpectedException( ArgumentOutOfRangeException::typeid )]
void Test_Something_That_Throws_Exception()
{
     throw gcnew ArgumentOutOfRangeException("Some more detail");
}
Run Code Online (Sandbox Code Playgroud)

只需使用::typeid例外:-)