Testing Silverlight Asynchronous Code

Coming! Version 1.7 will also support testing Silverlight asynchronous code with the help of the Silverlight Unit Test Framework. You can read about the background Ryan's post.

The facts (please consider them as beta):

Configure Specflow project to use async testing

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <configSections>
    <section name="specFlow"
      type="TechTalk.SpecFlow.Configuration.ConfigurationSectionHandler, TechTalk.SpecFlow"/>
  </configSections>
  <specFlow>
    <unitTestProvider name="MSTest.Silverlight4" />
    <generator generateAsyncTests="true" />
  </specFlow>
</configuration>

Use async operations from your step bindigns

The async support provides you several API methods for doing that.

<

table> API Method Description void EnqueueCallback(Action callback) Enqueues an action to be executed asynchronously. void EnqueueCallback(params Action[] callbacks) Enqueues a number of actions to be executed asynchronously, but consecutively. void EnqueueConditional(Func continueUntil) Enqueues an asynchronous and non-blocking wait until the condition returns true. The continueUntil predicate that must return true before the work queue is continued. void EnqueueDelay(TimeSpan delay) Enqueues an asynchronous and non-blocking wait for at least the given time before continuing. The delay is approximate, and not intended to be highly accurate. void EnqueueDelay(double milliseconds) Enqueues an asynchronous and non-blocking wait for at least the given time before continuing. The delay is approximate, and not intended to be highly accurate.

For accessing these API methods, you have two options currently.

  1. Derive your step binding class from TechTalk.SpecFlow.Async.AsyncSteps and use the methods inherited from the base class.
  2. Use AsyncContext.Current to access the API methods.