Click here to Skip to main content
15,892,005 members
Articles / Mobile Apps / Windows Mobile
Technical Blog

Windows Phone TDD Part 1: The Project

Rate me:
Please Sign up or sign in to vote.
4.67/5 (2 votes)
29 Jan 2014CPOL3 min read 4.1K   1  
Windows Phone TDD Part 1: The Project

Introduction

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:

  1. You can’t use Moq
  2. You can’t use NUnit (I don’t know if everybody has this problem, but Resharper test runner + NUnit don’t work for me)
  3. 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 of making 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 let's 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. Its 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 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.

Windows Phone TDD Part 2: Working with Caliburn.Micro

This article was originally posted at http://bogdanb.com/windows-phone-tdd-project

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer Feel IT
Romania Romania
Hey! I'm Bogdan Bujdea, a software developer from Romania. I started to learn programming since my first year of highschool with C++. During my time in college I tried various languages like Java, C#, Haskell, Javascript, Python, etc. but my favorite remains C#.
I started my career with Thinslices as a Windows 8 developer, but now I work for Feel IT Services as a Windows Phone developer.

Comments and Discussions

 
-- There are no messages in this forum --