c# - VSUTF、NUnit、xUnit.NET、MbUnit 与 SUTF 中的异步测试?

标签 c# nunit mstest mbunit 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();
            });
    }
}

最佳答案

Christopher Bennage 对此有一个有趣的方法,灵感来自 Caliburn Micro:

http://devlicio.us/blogs/christopher_bennage/archive/2011/01/17/improving-asynchronous-tests-for-silverlight.aspx

关于c# - VSUTF、NUnit、xUnit.NET、MbUnit 与 SUTF 中的异步测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8691397/

相关文章:

c# - VS 2010 : unable to unit test

c# - 在 VS 中运行单元测试与调试单元测试时,我应该期待什么区别?

c# - 运行测试时未调用 C# 中的 nUnit SetupFixture 类

c# - 创建堆积条形图

c# - 命名空间更改后的 DataContractSerializer 兼容性

c# - 如何在代码中重新排序 ToolStrip 项

c# - 验证列表已排序且项目具有特殊字符时获取 NUnit AssertionException

c# - 如何使用流畅的断言比较对象图中的嵌套列表

visual-studio-2012 - Visual Studio 2012 MSTest 与 NUnit 的优缺点

c# - 在更新方法中使用 LINQ - where 子句出现问题