How does one test async code using MSTest

Visual studio 2012 (previously known as “Visual Studio 11”) introduced support for async tests. It looks like this:

[TestMethod]
public async Task FooTest()
{
   var result = await SomeAsyncOperation();
   Assert.IsTrue(someCondition);
}

As noted in the comments, the Task return type is important. It won’t work if you declare the method as returning void.

Leave a Comment