loopback-api-testing

Simplified automated API testing for Loopback

Downloads in past

Stats

StarsIssuesVersionUpdatedCreatedSize
loopback-api-testing
2510.3.34 years ago7 years agoMinified + gzip package size for loopback-api-testing in KB

Readme

Loopback API Testing #
npm() npm()
This package is a simplified replacement for loopback-testing, which is now considered deprecated. It generates Mocha tests for Loopback API routes and examines their responses.
The main difference between this package and loopback-testing is that loopback-api-testing does not require you to write any code. Tests are specified in json format and the tests are generated automatically.
This package is not supported by, endorsed by, or associated with Strongloop or the core Loopback team.

Installing ##

npm install loopback-api-testing

Example Usage ##

The test file (e.g. test/loopbackAPI.test.js)
var loopbackApiTesting = require('loopback-api-testing');
var tests = require('./apiTestConfig.json');
var server = require('../server/server.js');
var url = 'http://localhost:3000/api';

loopbackApiTesting.run(tests, server, url, function(err) {
  if (err) {
    console.log(err);
  }
});

The test configuration JSON file (e.g. test/apiTestConfig.json):
[
  {
    "method": "GET",
    "model": "Users",
    "expect": 401
  }
]

Running the tests (for example):
mocha --reporter spec test

Should get you:
Loopback API
  ✓ should respond 401 on unauthenticated GET requests to /Users (67ms)


1 passing (318ms)

Making Authenticated Requests ##

You can specify a username and password in your tests to make the request as an authenticated user.
[
  {
    "method": "GET",
    "model": "Cars",
    "username": "my@user.com",
    "password": "myPassword",
    "expect": 200
  }
]

Making Requests with Data ##

You can send json data with a request.
[
  {
    "method": "POST",
    "model": "Cars",
    "withData": {
      "color": "blue"
    },
    "expect": 200
  }
]