How do I use ExpectedException in C++/CLI NUnit tests?

守給你的承諾、 提交于 2019-12-07 09:33:49

问题


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.


回答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 :-)



来源:https://stackoverflow.com/questions/1102792/how-do-i-use-expectedexception-in-c-cli-nunit-tests

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!