In my Pluralsight courses, I take you through each skill, step by step, but here I’d like to try giving you a lot of information at once, and see what comments you leave about the pace and quantity of information.
So let’s start a new project, not unlike the previous, but this time we’re going to build it out using unit tests and all the goodies of a real application. Again, fasten your seatbelts because we’re going to cover a lot of ground quickly.
Unit tests are small, fast tests that cover a very limited area of your code (typically a single statement or method). They should be:
- Fast. If it takes a long time to run a test, you won’t run it
- Self-explanatory: If you have to dig to find out what went wrong when a test fails, it is of little use
- Isolated: No test should depend on another test
- Repeatable: Re-running the test should give the same result if nothing else has changed
Unit tests can be used in three ways, and they are not mutually exclusive:
- You can use unit tests to make sure your code works
- You can use unit tests to help design your code
- You can use unit tests to ensure that any refactoring you do doesn’t break anything
Most of us use unit tests in the first and third way; but there is great power in the second approach which is often overlooked.
This post will not be a comprehensive look at Unit Tests (that would take a book) but we’ll use unit tests and see how they are created and used as we go.
nUnit, xUnit, or Something Else
The two most popular unit testing frameworks for Xamarin applications are probably nUnit and xUnit. nUnit has the advantage that it comes with Xamarin Studio; xUnit is a bit harder to set up but runs like any application on your phone and thus offers lots of advantages such as the ability to easily step through your test code.
For this series, I’ll use xUnit.
We’re going to build a Project tracker. The idea is that a developer (or lawyer, etc.) might be working on more than one project. This little app will help you keep track of how much time you spend on each. Here’s what it looks like…
We’ll build this with a strong focus on the logic and not much on the UI (as you can see). Can’t wait to get started.
Special thanks to Greg Shackles without whom this example would be just a twinkle in my eye
52 Weeks of Xamarin
- 52 Weeks of Xamarin: Week 1
- 52 Weeks of Xamarin: Week 2 – Starting the project
- 52 Weeks of Xamarin: Week 3- Events in Xamarin.Forms
- 52 Weeks of Xamarin: Week 4 – Creating the Model and Saving
- 52 Weeks of Xamarin: Week 5 – Diving in the deep end
- 52 Weeks of Xamarin: Week 6 – Starting xUnit Testing
- 52 Weeks of Xamarin: Week 7 – First Unit Tests
- 52 Weeks of Xamarin: Week 8 – Testing the View Model
- 52 Weeks of Xamarin: Week 9 – Databases part 1
- 52 Weeks of Xamarin: Week 10 – The UI for our database program
- 52 Weeks of Xamarin: Week 11 – Customized Controls for Xamarin.Forms
- 52 Weeks of Xamarin: Week 12 – Advanced Customized Controls
- 52 Weeks of Xamarin: Week 13 – Writing It Thrice
- 52 Weeks of Xamarin: Week 14 – Thrice (part 2)
- 52 Weeks of Xamarin: Week 15 – Creating an iOS Application Part 1
- 52 Weeks of Xamarin: Week 16 – Creating an iOS Application Part 2
- 52 Weeks of Xamarin – Week 17