There are methods that return a Task<T>. While testing such methods, a common mistake is to make assert statements, without waiting for the task to complete.

While I wrote a few test methods like the above, all those test methods succeeded repeatedly. I was doing integration testing and I expected the test methods to fail. It was a while before I realized that the test method has exited without making the assertions. So, I modified the Test method as below:

The Wait method ensures that the Test method does not exit without making the assertions.

Ensure that the Task gets completed before exiting the Unit Test method
Tagged on:     

Leave a Reply

Your email address will not be published. Required fields are marked *