Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I'm writing some super simple async code. Just saving a file off-thread.

I'd like to test this code using the MSTest unit test framework in Microsoft Visual Studio Team System 2008.

How do I do this?

I'd like to simple block the test method until the method returns. I can imagine some ways to do this, but I'm blown away there aren't any best practices or helper classes around this.

I see a lot for Silverlight, but nothing generic.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
563 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...