Skip to content

zipymonkey/loopback-api-testing

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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": "[email protected]",
    "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
  }
]

About

Simplified automated API testing for Loopback

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%