Windows Phone TDD Part 1: The Project3 min read
As I mentioned in my previous article, I recently started to learn Test Driven Development. Although the hardest part for most developers is getting used to writing tests first, for Windows Phone developers there’s another problem, the project setup. There is a “Windows Phone Unit Test App” project template available in Visual Studio, but it has three major disadvantages:
- You can’t use Moq
- You can’t use NUnit(I don’t know if everybody has this problem, but Resharper test runner + NUnit don’t work for me)
- You can’t use Ninject
Ok, so it may seem that it’s just about some libraries that I prefer, but the first one is actually very important. Tests have to be fast, so it’s crucial to mock anything that you don’t control, like DB transactions, web requests, storage API, etc. You can’t do TDD if you can’t mock your code.
I was thinking to make a simple tutorial that will show you only the project setup, but why stop here? I will show you how to create an app from scratch and make tutorials along the way, until it’s published. You will learn how to use Moq, NUnit, Caliburn.Micro, SpecFlow, PCL and many other things. The tools that I’ll be using are:
Now lets’ talk about the app. I don’t really care about it, I’m not planning on making money from it so it will be free and it won’t have ads. It’s only purpose will be to help you learn TDD. That’s why I will use a Bitbucket repository and make the source code public.
So what should the app do? What’s the “hello world” of unit testing tutorials? The Calculator of course… but it’s too simple, so I’ll try to make it a little bit more complicated. I will make some sort of live budget. When I write the tasks for a project, I like to use the “As a <type of user>” template(here are some good reasons for this), so here are the features:
- As a user, I want to add my monthly budget and set a time period for it
- As a user I want to be able to add expenses
- As a user I want to be able to add incomes
- As a user, I want to see how much do I earn for a period of time(day/minute/second/etc.)
- As a user I want to pin a live tile with my current budget
These are the requirements for now, but I will add some more until the end of the project. Of course it would be easier to think about it from the start so I won’t have to change anything during development, but in real life it’s not like this. Clients change their mind very often, and you have to remove or change features during development(if it’s possible). One of the goals of these tutorials is to show you how easy it is to change and refactor the code if you’re doing TDD, so that’s why I will think about some more features later. If you have ideas for new features along the way, you can leave in the comments and I will add as many as I can. My plan is to finish the app until the the end of February. It may seem a long time, but I’m also a full time developer so I won’t be working every day at this app.
Now that we have everything figured out, let’s start working. In the next tutorial, you will learn how to add Caliburn.Micro to a Windows Phone project.
TDD posts series:
- Windows Phone TDD Part 1: The Project
- Windows Phone TDD Part 2: Working with Caliburn.Micro
- Windows Phone TDD Part 3: Writing the first test