How to perform integration testing in a Noje.js RESTful application?

Given an existing Node.js application that implements a RESTful API with the JSON format, what would be a good option for writing an integration testing package in Node.js?

This set should execute test scripts, which usually consist in setting the database in a known state (possibly through POST requests) and perform a series of tests with GET, POST, PUT and DELETE requests, checking the returned status codes and responses.

+4
source share
1 answer

There are several options for module testing modules.

I will show examples with expressions and vows.

var assert = require('assert'), http = require('http'), server = getServer(); // get an instance of the HTTPServer assert.response(server, { 'url': '/' }, { 'body': "test body", 'status': "200" }); 

And the example with vows-is

 var is = require("vows-is"); is.config({ server: { "factory": createServer, "kill": destroyServer, "uri": "http://localhost:4000" } }) is.suite("integration tests").batch() .context("a request to GET /") .topic.is.a.request("GET /") .vow.it.should.have.status(200) .vow.it.should.have .header("content-type", "text/html; charset=utf-8") .context("contains a body that") .topic.is.property('body') .vow.it.should.be.ok .vow.it.should.include.string("hello world") .suite().run({ reporter: is.reporter }, function() { is.end() }); 

vows-is is a subtle abstraction on top of a vow to make testing easier.

However, vows are under active development, so use at your own risk.

+4
source

All Articles