NUnit 抛出 System.InvalidOperationException:"All test threads are blocked."

NUnit throws System.InvalidOperationException: "All test threads are blocked."

今天我去 运行 我的 NUnit 测试,突然发现大量失败!几乎所有失败的原因都是一样的:

System.Reflection.TargetInvocationException : Exception has been thrown by the target of an invocation. ----> System.InvalidOperationException : All test threads are blocked. Did you start new threads that the test doesn't know about?

当我用谷歌搜索这个异常时,我没有发现它与 NUnit 有关。有人以前看过这个吗?

希望我能在下面发表评论,但无论如何,您使用的是哪种 NUnit 适配器?

发现 issue 使用 NUnit 适配器 3.0.0.0

报告

我想通了!

我做了一个更改,导致大量测试永远等待从未发生过的事情。这在一些测试中表现为永远挂起,而在其余测试中表现为提高上述 InvalidOperationException.

因此,简而言之,当您的许多测试永远挂起并且 NUnit 尝试并行化测试时,它会用完线程并抱怨。

我最初发布这个问题并不是因为我的测试失败了,而是因为当我用谷歌搜索神秘异常时那里没有资源。希望这个答案可以帮助以后被这个错误迷惑的其他人。