Skip to content

JoaoDiogoFalcao/Node-API-Testing

Repository files navigation

Alt text Express API Testing

An example on how to test your server API using Superagent. Reference for Integration Testing lab for FSE Fall 2015 at CMU-SV.

Install

  1. Install needed tools using: npm install -g grunt-cli mocha istanbul (optional)
  2. Install needed dependencies using: npm install

Tests results (local)

  • grunt test

How to initialize server for testing

On test/users-api.js start the server by including the following:

var debug = require('debug')('Node-API-Testing');
var app = require('../app');

app.set('port', PORT);
app.set('testing', true);

var server = app.listen(app.get('port'), function() {
  debug('Express server listening on port ' + server.address().port);
});

Shippable integration - CI

Alt text

  • Link your account with shippable by following Step 3: Enable CI/CD for repos.

  • After the account is linked, when you push changes to the repo shippable will run your tests and code coverage.

  • You can see the results under Tests.

  • Note that code coverage will not work for this case. This happens because the app is being tested from the outside using superagent. istanbul sees the app as a black box.

Test Results

Alt text

Code Coverage

Alt text

About

An Example on how to do Integration testing using Node and mocha

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published