I attempt to have unit tests run automatically when I make changes to files, and try out some different solutions for this with JS Test Driver and LiveReload.

Automated testing

I have tried several types of automated testing over the past few weeks, and after working through some interesting potentials, have come across what seems to be a viable solution.

The types of automated testing that I have been trying out in regard to Jasmine are:

  1. JS Test Driver  using the jasmine-jstd adaptor – which lets you run tests from a command-line interface
  2. Jstdutil which reruns JS Test Driver whenever monitored files change
  3. LiveReload with a LiveReload Chrome extension, that allows Sublime Text to automatically reload the web page

What is wanted

Jasmine is effective for creating unit tests, but I don’t want to have to switch over to a web browser and refresh it to run them each time. I want to be lazier and more effective than that. JS Test Driver has the same problem but in a command-line environment instead.

I want to have tests automatically run as I write the code. Having those tests run in a wide range of test environments would be a beneficial bonus too.

How they perform

JS Test Driver

JS Test Driver was looking promising, but only when a small number of tests were involved. With more than about 50 tests, the process with JS Test Driver ends up being far too slow.

The times to run 186 different tests are:

  • JS Test Driver – 166 seconds
  • Jasmine in a web browser – 1/3 of a second

So something is definitely wrong there. As a result it’s goodbye to JS Test Driver and sadly to jstdutil until I can dig deeper to find the cause of the problem.

LiveReload

LiveReload is currently the most effective solution. With that I have a Sublime Text package, and a Chrome extension that connects with it. As soon as a file is saved, the web page is instantly reloaded to show the result of the tests on the updated code.

LiveReload is very successful at making the testing easier to perform, but using a web page to run the results does result in a lot of screen real-estate being dedicated to the task.

Other alternatives

Another possible option that I’ve just recently found out about is using TestEm along with the PhantomJS headless web browser. Tomorrow I’ll look in to that as another potential solution. , but for now LiveReload does the job quite well.

Advertisements