2012-01-01 50 views
6

Silverlight单元测试框架具有一个[Asynchronous]属性(AsynchronousAttribute),该属性使得测试仅在调用EnqueueTestComplete()时结束。这允许一种简单的方法来编写需要等待事件发生的测试才能结束。现在我试图从最受欢迎的选择中选择一个最喜欢的通用单元测试框架 - VSUTF,NUnit,xUnit.NET,MbUnit,我想知道 - 您将如何使用这些框架进行异步测试?VSUTF,NUnit,xUnit.NET,MbUnit与SUTF的异步测试?

我想我可以推出一些自定义代码,将执行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(); 
      }); 
    } 
} 

回答

1

的Visual Studio现在支持有async Task签名和测试完成的异步方法完成时的测试。