what will NUnit do internally when a test timeout is violated?

别来无恙 提交于 2019-12-05 13:44:02

If a test method in NUnit specifies a timeout then it will be run on a separate thread from the rest of the tests. If the test exceeds it's timeout the created thread will be rudely aborted via Thread.Abort.

The part about the abort is not explicit in the documentation but is evident upon digging into the NUnit code base. See TestThread.RunTest for the details.

EDIT*

The reason the test fails when it times out, even though you catch the exception, is because the test is marked as failed before it aborts the thread. Hence whether or not it's expected is meaningless because it's already marked as failed.

NUnit never causes an exception to magically appear from inside your code. The NUnit test runner is running your code from with a thread and aborts that thread if it takes longer than the specified timeout.

When the thread running your code is aborted a ThreadAbortException is generated. Since NUnit knows it caused this exception itself, adding an ExpectedException(typeof(ThreadAbortException)) isn't going to cause the test to pass.

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