Showing posts with label Constructor Pattern. Show all posts
Showing posts with label Constructor Pattern. Show all posts

12/03/2012

Building a Unit Test in Jasmine, Part 3

We created a Jasmine unit test example in the first two parts of this series that started with a statement and then abstracted out to an object.  This time we will expand the object to be more robust.  Most importantly, we are not changing the tests currently in place.  

The JasmineTester is going to be updated to accept a random number of values.  The first step is to create a unit test to describe this.  The number of properties being added is upped to 4.  The new test will check to make sure the new object constructor still returns an object by using the toBeDefined matcher.

11/26/2012

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.