我在我的测试代码中有这个断言
Assert.That(() => eventData.Count == 0,
Is.True.After(notificationPollingDelay),
"Received unexpected event with last event data" + eventData.Last().Description());
在一段时间后断言某些条件,如果失败则输出一个消息。它运行失败是因为消息字符串在断言开始时构建而不是在断言结束时构建。因此eventData
集合仍然为空(初始状态),尝试获取集合中最后一项的Description
会失败。在NUnit
中是否有解决方法或更好的替代方案?还是我必须回到在我的测试中使用Thread.Sleep
?
PS:我正在使用NUnit 2.5.10。
After
是一个延迟约束 http://www.nunit.org/index.php?p=delayedConstraint&r=2.6.2。 - Mike Two