Unit testing, Jasmine, PhantomJS

Date 07/10/2014

Second assignment is given.

Unit testing in general

Unit testing, as the name suggests, is a way of testing units or portions of code.

PhantomJS, a headless WebKit browser

In an environment where there is no availability of screens, such as a server, continuous integration server specifically, is a need for tools which do not require the screen. One such tool specifically made for browser based testing, is PhantomJSarrow-up-right.

However the latest release of PhantomJS, v1.9.8 from October 2014, is based on a WebKitarrow-up-right from 2011. The next major release (v2.0.0) should be out soon and it will be based on a much newer WebKitarrow-up-right, via Qtarrow-up-right v5.3 which is used underneath.

Tasks for the day

  1. Add unit tests to your hello-node-js repository by using nodeunit

    • Unit test spec files are placed in a directory called tests

    • Each unit test file named as its targeting source file and _spec.js suffix

  2. Add a task runner task for running the unit tests

    • Make sure that tests can be run after a fresh clone of the repository,

      followed by npm i and [task runner] test, for example grunt test

Examples for the tasks

1. Unit tests with nodeunit

Install dependencies first:

Create directory for tests and initial empty test file:

The test can be written as the following JavaScript, assuming that the LICENSE file exists in the repository and its modification date is in October 2014.

Run the tests with:

2. Task runner for the unit tests

Last updated

Was this helpful?