Asynchronous tests in VSUTF, NUnit, xUnit.NET, MbUnit vs. SUTF?
Asked Answered
C

2

7

Silverlight Unit Test Framework has an [Asynchronous] attribute (AsynchronousAttribute) that causes the tests to only end when EnqueueTestComplete() gets called. This allows for a simple way to write tests that need to wait for an event to occur before they end. Now I am trying to pick a favorite general purpose unit test framework out of the ones that seem to be the most popular choices - VSUTF, NUnit, xUnit.NET, MbUnit and I was wondering - how you would do asynchronous testing using these frameworks?

I suppose I can roll out out some custom code that will do Monitor.Wait or ResetEventWaitOne and call it at the end of the test method, then do a Pulse/Set when the test is over, but I was looking if there is an existing common/built-in solution.

This is a sample of how it is done in SUT (from 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();
            });
    }
}
Chaim answered 1/1, 2012 at 1:21 Comment(0)
C
1

Visual Studio now supports tests that have the async Task signature and the tests complete when the async method completes.

Chaim answered 6/6, 2013 at 21:37 Comment(0)
A
1

Christopher Bennage has an interesting approach to this, inspired by Caliburn Micro:

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

Armlet answered 6/1, 2012 at 16:6 Comment(1)
This is still the Silverlight Unit Test based solution though from what I could see. What about other, non-Silverlight frameworks?Chaim
C
1

Visual Studio now supports tests that have the async Task signature and the tests complete when the async method completes.

Chaim answered 6/6, 2013 at 21:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.