我有這樣的斷言在我的測試代碼延遲NUnit的斷言消息評估
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。
據我所知,這不是本機NUnit斷言的語法。你使用哪個斷言庫? –
@DanielHilgarth - 使用基於約束的模型時,這是有效的NUnit斷言語法。 '後'是一個延遲的約束http://www.nunit.org/index.php?p=delayedConstraint&r=2.6.2 –
@manojlds:謝謝你的信息。對於任何感興趣的人:[DelayedConstraint](http://www.nunit.org/index.php?p=delayedConstraint&r=2.5.10)結合[EqualConstraint](http://www.nunit.org/index.php) ?p = equalConstraint&r = 2.5.10)使用[基於約束的斷言模塊](http://www.nunit.org/index.php?p=constraintModel&r=2.5.10)。 –