This is another in Robert’s Getting Started series, where he provides an introduction to a topic that everyone knows about but not everyone is actually doing (or doing enough of). In this episode, part 1 of 3, Robert shows how to get started with unit testing in Visual Studio. The primary goal of unit testing is to take the smallest piece of testable code in an application, isolate it from the remainder of the code, and determine whether it behaves exactly as you expect. Each unit can be tested separately and can easily be tested over and over again.
In this episode, he shows how to write unit tests that test the UI interactions in a XAML application. He then shows how to create data-driven tests and how to perform a code coverage analysis to determine what parts of your code are being covered by unit tests.
In this episode, Robert wraps up his 3 part series on unit testing. He shows how to use Microsoft Fakes, which enable you to replace a method call with a stub or shim in your unit tests. For example, you can declare, for the purpose of running a unit test, that a call to a random number generator always return 6 or that a call to the Save method of a service always returns true. That way, you can test the rest of the code in that unit. Robert then shows how to configure continuous integration with Visual Studio Online. Once you do that, all of your unit tests will be run every time you check in code.
You can find the sample code and demo scripts for the entire 3 part series here.