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

发布于 2024-07-26 10:20:50 字数 290 浏览 3 评论 0原文

如何

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

在 C++ 中执行相当于:...的操作(这里的示例是 C#)? 据我所知,NUnit 的 C++ 实现没有 typeof() 函数。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

小矜持 2024-08-02 10:20:50

为了避免其他人花费很长时间试图找到它,解决方案如下:

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

只需使用异常的 ::typeid :-)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文