Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
This node module is used to create automated acceptance tests. It's also a great alternative (or complement) to client test tools such as Selenium. You write your tests in a heartbeat and run them using the command line.
JavaScript
Tree: d4b7a99c03

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
CHANGELOG.md
README.md
cli
dokimon
package.json

README.md

Dokimon

This is a node module used for setting up automated tests of various kinds. It may also be used as an alternative (or complement) to client test tools such as Selenium. You write your tests in a heartbeat and run them using a command line interface.

Example usages:

  • Verify that your online services is up and running
  • Verfify that your RESTfull API is responding and behaving as expected
  • Validate that your website generates expected html code

Getting started

1) Install node and npm

Take a look at http://nodejs.org if you don't already have node and npm installed since before

2) Create project directory and install dokimon

Create a directory where you find suitable, go to the directory in your shell interpreter and run npm install dokimon

4) Create test directory

You write your tests in files that has the extension .djs (more information about writing the tests below).

3) config.json

This file should be placed in the root of your project directory and contain a JSON object with the properties "host", "verbose" and "testdir".

  • host (String) — Specifies against which host you're going to run the tests.
  • verbose (Boolean) — Makes it possible to get a more verbose output when running the tests
  • testdir (String) — Relative path to the directory where you have your test scripts. This directory should be placed in the project directory.

It's possible to change all of these paremeters on the fly when using the command line interface. It's also possible to completely switch to another configuration file when using the command line interface. Dokimon will search for a file named config.json in current working directory if not specified when running the tests.

Example config.json

{
  "host" : "api.myservice.com",
  "verbose" : false,
  "testdir" : "tests"
}

Example project layout

/Users/john/nodetests/
    tests/
      - myscript.djs
    - config.json

Writing tests

You can have one or several dokimon scripts, each containing one or several tests. All dokimon scripts should have the extension .djs and be located in the test directory defined in config.json. The scripts is written as ordinary node modules (http://howtonode.org/creating-custom-modules).

Basic example (myscript.djs)

var dokimon = require('dokimon'),
    assert = require('assert');

var checkHomepage = new dokimon.Test(
  'HomePageIsRunning', 
  {url : '/'}, 
  function(res, body) {
    assert.equal(res.statusCode, 200, 'My website is not responding');
  }
);

module.exports = checkHomepage;

You can also export an array with tests.

var dokimon = require('dokimon'),
    assert = require('assert');

var checkHomepage = new dokimon.Test(
  'HomePageIsRunning'...
);

var checkSiteSearch = new dokimon.TestPostForm(
  'SearchIsWorking', 
  {
    url : '/search/',
    write : {s : 'hockey', sortby : 'date', sortorder : 'desc'}
  },
  function(res, body) {
    assert.equal(res.statusCode, 200, 'Search is down');
    // and some other assertions that validates expected search result
  }
);

module.exports = [checkHomepage,checkSiteSearch];

Assuming that I've written this code in a file residing in my test directory (defined in config.json) and that the file has .djs as extension I can now run my tests by calling dokimon -r in the project directory. I can also choose to only run one the tests like dokimon -rs myscript HomePageIsRunning

Read more about writing tests here

CLI

dokimon -r

Run all dokimon scripts in the test directory defined in config.json

dokimon -r api website

Run the scripts named api.djs and website.djs residing in the test directory defined in config.json. You can also write the paths to the scripts, -r tests/api.djs tests/website.djs

dokimon -rs website HomePageIsRunning

Run the test named HomePageIsRunning that's located in the script website.djs residing in the test directory defined in config.json

dokimon -l

List all scripts (and their tests) that is located in the test directory, defined in config.json

dokimon -s website

List all available tests in the script website.djs

Optional arguments

-verbose - Gives you a more verbose output when running the tests

-config /Users/john/dokimon/production.json - Use another config file than the one that is automatically loaded by dokimon

-host stage.myservice.com - Override the host defined in config.json

-testdir /var/nodetests/ - Use another test directory than the one defined in config.json

Something went wrong with that request. Please try again.