Solve the Problem, Not the Behavior

In my past life of consultancy I became very used to working on other people's code.  One of the most important lessons I learned was to "find the problem first".  Errors are a behavior you witness.  Debugging is fixing those errors.  Most developers would consider those reasonable statements.  There is an underhanded trick here though.  Some developers might make the mistake of a direct connection between the two, but there isn't.  The error you witness may not be the error you need to fix.


Building a Unit Test in Jasmine, Part 2

In the previous part, I showed an extremely simple test whose only purpose is to highlight how Jasmine works. This post will take those pieces and start doing something more dynamic with our source code. The Source and the Spec are going to change.

One reason to unit test is to confirm your code works despite internal changes to the source. As your application changes and matures, it can be daunting to ensure your old code still works. Properly created and maintained unit tests make this much less scary. You add a feature, run all your tests. Everything passes, then you are in good shape. If something breaks, you know it now and not when the customer finds it. Once everything passes you can move on to your next set of changes with relative certainty your application still works.  This post will set us up to show that principle in action over the next 2 posts.


Building a Unit Test in Jasmine, Part 1

(Thanks to Dustin Butler for the inspiration that led me down this path.  His great and more in-depth article is at Unit Test JavaScript Applications with Jasmine)

Unit testing and I have had a tumultuous affair until now.  Every few months I would pick up a book, go on a blog reading binge, or try out a framework.  It would never work out.  I would get frustrated or work would intervene and off I went.  Unit testing and I were almost fated to always be apart... <cue the romantic music>
An opportunity came at work to create a new feature on our web platform.  I decided to take a chance and build it from unit tests.  It was a great opportunity to start clean with very few dependencies to worry about.  The lack of entanglements made it easier for me to understand how unit testing would work to describe this new piece.