Fil*_*kun 7 c# mbunit nunit mstest xunit.net
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();
});
}
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
625 次 |
最近记录: |