O'Reilly logo

Programming Windows Store Apps with C# by Iris Classon, Matthew Baxter-Reynolds

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Appendix B. Unit Testing Basics for Windows Store Apps

I’m being very careful to call this section “Unit Testing Basics,” emphasis on the “Basics.” Describing unit testing is beyond the scope of this book, and my objective here is to provide a basic outline of unit testing for total newbies. Specifically, I’m looking to show how the integrated unit-testing features work in Visual Studio 2012, and finally demonstrate that what we’ve done in the book is unit-testable.

We’ve gone to great lengths in our project to use MVVM—a very common objective of which is to provide unit-testing vectors. The question is, does it work?

Unit Testing for Newbies

If you’re not using unit testing in your day-to-day work, you should be. Unit testing is like having a savings account and the spare cash and discipline to put a little aside each month. There’s a little upfront pain, but when you need it, you’ll be extremely glad it’s there.

The principle of unit testing is based on the truism of software engineering that “system in known state plus known value yields predictable result.” So, if you have a method that multiplies two values together, you can create a unit test that plugs in two known values and checks against a known result. The principle is that if you happen to break that method somewhere down the line, you’ll be told about it before it ends up in the customer’s hands.

So a typical test might look like this:

// test the results of multiply...
private void TestMultiply()
{
  // make sure that the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required