Silverlight 单元测试框架有一个 [Asynchronous] 属性 (AsynchronousAttribute),它导致测试仅在调用 EnqueueTestComplete() 时结束。这允许一种简单的方法来编写需要等待事件发生才能结束的测试。现在我试图从似乎是最受欢迎的选择中挑选一个最喜欢的通用单元测试框架——VSUTF、NUnit、xUnit.NET、MbUnit,我想知道——你将如何使用这些框架进行异步测试?
我想我可以推出一些自定义代码来执行 Monitor.Wait 或 ResetEventWaitOne 并在测试方法结束时调用它,然后在测试结束时执行 Pulse/Set,但我正在查看是否存在是现有的通用/内置解决方案。
这是在 SUT 中如何完成的示例(来自 http://smartypantscoding.com/a-cheat-sheet-for-unit-testing-silverlight-apps-on-windows-phone-7)。
[TestClass]
public class AsyncTests : SilverlightTest
{
[Asynchronous]
[TestMethod]
public void AsyncAppendStringTest()
{
var appendStrings = new List<string>() { "hello", "there" };
StringJoiner.AsyncAppendStringsWithDashes(appendStrings, (returnString) =>
{
Assert.IsTrue(string.Compare(returnString, "hello-there") == 0);
EnqueueTestComplete();
});
}
}
最佳答案
Christopher Bennage 对此有一个有趣的方法,灵感来自 Caliburn Micro:
关于c# - VSUTF、NUnit、xUnit.NET、MbUnit 与 SUTF 中的异步测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8691397/