NUnit辅助线程异常
我正在测试启动辅助线程的代码。而且这个线程有时会抛出异常。我想编写一个测试,如果没有正确处理该异常,该测试就会失败。
我已经准备好了该测试,我在 NUnit 中看到的是:
LegacyImportWrapperTests.Import_ExceptionInImport_Ok : PassedSystem.ArgumentException: aaaaaaaaaa
at Import.Legacy.Tests.Stub.ImportStub.Import() in ImportStub.cs: line 51...
但该测试被标记为绿色。那么,NUnit 知道该异常,但为什么它会将测试标记为“通过”?
I'm testing the code which starts a secondary thread. And this thread sometimes throws an exception. I'd like to write a test which fails if that exception isn't handled properly.
I've prepared that test, and what I'm seeing in NUnit is:
LegacyImportWrapperTests.Import_ExceptionInImport_Ok : PassedSystem.ArgumentException: aaaaaaaaaa
at Import.Legacy.Tests.Stub.ImportStub.Import() in ImportStub.cs: line 51...
But the test is marked as GREEN. So, NUnit knows about that exception, but why does it mark the test as Passed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以在输出中看到异常详细信息并不一定意味着 NUnit 知道该异常。
我使用了
AppDomain.UnhandledException
< /a> 事件在测试期间监视此类场景(假设异常未处理,我假设这里就是这种情况):如果您只想测试特定异常,您可以在事件处理程序中执行此操作:
That you can see the exception details in the output does not necessarily mean that NUnit is aware of the exception.
I have used the
AppDomain.UnhandledException
event to monitor scenarios like this during testing (given that the exception is unhandled, which I assume is the case here):If you want to test only for specific exceptions you can do that in the event handler: