a blog for those who code

Wednesday 2 December 2015

Containerized Unit Testing Nodejs Applications with Dockunit

In this post we will be discussing about Dockunit an application for containerized unit testing across any platform for Nodejs Applications. Dockunit is a utility for running containerized software tests. Dockunit let's you defined a set of Docker containers to run your tests against.



The Requirements of Using dockunit are :

1. It works only in OSX or a Linux Environment
2. Node.js and Npm should be installed
3. Docker

Installation : Dockunit can be installed via npm using npm install -g dockunit

Usage : We need to be able to run all our tests locally across a number of Node versions which will be done using Dockunit. We will create a file called Dockunit.json on the root of the folder. Each and every projects should have their own Dockunit.json file. Example of Dockunit.json is :

{
  "containers" : [
    {
      "prettyName": "Test1",
      "image": "node:0.10.0",
      "beforeScripts": [
        "npm install",
        "npm install -g mocha"
      ],
      "testCommand": "mocha"
    },
    {
      "prettyName": "Test2",
      "image": "node:4.0.0",
      "beforeScripts": [
        "npm install",
        "npm install -g mocha"
      ],
      "testCommand": "mocha"
    }
  ]
}

Dockunit.json defines what test commands should be run on what types of containers for the project. prettyName is used to identify the container. image is a valid Docker container image located in the Docker Registry. Docker comes with the predefined Nodejs images which you can use. beforeScripts allows you to run commands in the Docker container before the test command is run. testCommand is the actual test command to run on each container.

Run Dockunit : dockunit 

Please Like and Share CodingDefined.com Blog, if you find it interesting and helpful.

No comments:

Post a Comment