Skip to content

Starter kit for using SuperTest with MochaJS to do HTTP REST API testing

Notifications You must be signed in to change notification settings

almamedia/rest-api-testing-starter-kit

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

REST API testing starter kit

SuperTest REST API testing with Mocha. This is a starter kit which you can copy to your own projects.

Installation

  • Requires NodeJS v0.10 or newer

Install Nodemon and Mocha globally:

npm install -g nodemon mocha

Install local depedencies:

npm install

Running the server and testing it

Run the example server:

npm start

Test locally:

npm test

Test on continuous integration

Set an environment variable export CI=true (note: e.g. Travis-CI sets this automatically) in your continuous integration environment or just prepend the variable before the test command:

CI=true npm test

This outputs the test results as "standard-ish" XUnit XML.

Writing tests

Test suites must be stored in ./test/suites/-folder. If you wish, you can also organize your test suites into folders (maximun 2 levels deep).

A test suite must exposed as CommonJS module function which takes the supertest's request object (in this case called API) as an argument. Suite must have at least one MochaJS describe-block inside them.

Here's an example structure:

module.exports = function(API) {

  describe('Describe your test suite here', function() {
    it('should do something', function(done) {
      /* some tests */
    });
  });

}

See the provided examples root endpoint test and collection test for more examples.

About

Starter kit for using SuperTest with MochaJS to do HTTP REST API testing

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published