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

时间:2021-08-11 15:40:37

How do you do the equivalent of:

你怎么做相当于:

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

...in C++ (the example there is C#)? As far as I can see, there's no typeof() function for the C++ implementation of NUnit.

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

1 个解决方案

#1


To avoid anyone else hunting around for ages trying to find it, here's the solution:

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

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

Simply use the ::typeid of the exception :-)

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

#1


To avoid anyone else hunting around for ages trying to find it, here's the solution:

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

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

Simply use the ::typeid of the exception :-)

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