Tuesday, February 23, 2016

Using the Async keyword in Visual Studio Unit Tests

I was recently attempting to use the async keyword with some of my Visual Studio Unit Tests for ASP.NET Web API and I soon discovered that every time I attempted to run my Unit Tests, they always came up Inconclusive!!

Well, as it turns out, Visual Studio Unit Tests DO NOT support the async keyword!!

So how do you work around this problem?


var actual = testAPIController.Get().GetAwaiter().GetResult() as OkNegotiatedContentResult<List<string>>;


Using this code segment allows you to still use the same Unit Test method signatures and test asynchronous ASP.NET Web API methods!

No comments:

Post a Comment