我有一些产生无限循环的代码。现在我需要编写一个将在大约 200 毫秒后失败的测试。 200ms表示代码进入死循环。
例如:
public void CodeUnderTest()
{
while(true)
{
}
}
最佳答案
使用 MSTest 时,您可以使用属性
[TestMethod]
[Timeout(200)]
参见 How to force tests to stop running
You can set time limits with which the execution of a test or a test run will comply. You might need to do this, for example, if you work in a test lab and need a test run to complete by a certain time of day.
Another scenario for the use of time limits is that of non-responsive code.
关于c# - 如何使陷入无限循环的测试失败?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12145510/