52 Weeks of Xamarin: Week 5 – Diving in the deep end

AngerFor the past four weeks, we’ve been reviewing the fundamentals of Xamarin.  Let’s stop for a bit and talk about how we really code, and how we should.

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

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.

The Project

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…

ProjectTrackerRunning2

 

 

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

 

 

Share

About Jesse Liberty

Jesse Liberty is an independent consultant and programmer with three decades of experience writing and delivering software projects. He is the author of 2 dozen books and multiple Pluralsight courses, and has been a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a Xamarin Certified Mobile Developer and a Xamarin MVP, Microsoft MVP and Telerik MVP.
This entry was posted in Essentials. Bookmark the permalink.

3 Responses to 52 Weeks of Xamarin: Week 5 – Diving in the deep end

  1. GeoCoder says:

    I don’t understand. Is this post incomplete? Do we start the project next week?

  2. Gareth Arch says:

    OK, so are you building a Project Tracker project or a To Do project? I understand throwing a lot of stuff at us, but you seem to be going back to week 1 again.

    • We are starting a new project that will build on what was already covered. This new project will allow us to start with unit tests (to a degree test-driven) and will allow for a more full fledged application.

      Thanks for your patience as I get this going.

Leave a Reply

Your email address will not be published.