One of the questions I often receive from developers starting with unit testing, is how we can test private methods. Here is my perspective on that. There are several ways to approach it: 1) Make the method public. 2) Extract the private method to its own class where it can be public and therefor tested… Read More

On one of our projects we structure our front-end JavaScript code using RequireJS modules, ensuring predictable load ordering and better encapsulation. When writing unit tests for code that depends, directly or indirectly, on one or more other modules, we often want to mock some of those modules to make our unit tests more focused giving… Read More

Most JavaScript-based Model-View-Controller frameworks make it very easy to write unit tests for the Model, and reasonably easy to write unit tests for the Controller. However, writing unit tests for the View is often seen as more difficult. This is no different with AngularJS, where most guidelines argue for end-to-end testing to get good test… Read More

When running our automated tests, we sometimes need a running web server. A back-end example is when we write (integration) tests against our web service end-points. A front-end example is when we use the text-plugin for RequireJS to load HTML templates ( We can have multiple build jobs running on our CI-server, which is useful… Read More

A couple of months ago I linked to a presentation on advanced unit testing techniques for front-end JavaScript using Jasmine. This week I did a presentation for a client using QUnit instead, covering roughly the same subjects: Mocking and spy techniques to avoid dependencies on Functions, methods and constructor functions Time (new Date()) Timers (setTimeout,… Read More

I recently gave a presentation at a meetup in Pleasanton, California on fast feedback. One of the cornerstones in Agile development is fast feedback. For engineering, “fast” means “instantly” or “in 5 minutes”, not “tomorrow” or “this week”. Your engineering practices should ensure that you can answer yes to most of the following questions: Do… Read More

Unit testing front-end JavaScript presents its own unique set of challenges. Yesterday we had another event in the Test Driven Developers Bay Area meetup group. At this event I presented a number of different techniques to tackle these challenges and make our JavaScript unit tests fast and robust using Jasmine (another version using QUnit). I… Read More

I’ve previously described how to run your QUnit tests and produce a coverage report on every commit. This works great if you happen to have chosen QUnit as your unit testing framework. Jasmine is another popular JavaScript unit testing framework. Here I will show how you can get the same automated feedback from your Jasmine… Read More

Being able to get fast feedback from failing unit tests is useful. And if you could easily identify the parts of your code that you still need to write tests for, you would get more comprehensive feedback. There is a plugin for Grunt that can use the JSCoverage tool to produce a coverage report while… Read More

Being able to check the quality of your code on every commit is useful. But it would be even more useful if you could also run all your unit tests on every commit. Here I will show how you can extend the automated build setup to also run all your QUnit tests. (Switch to different… Read More