Posts

Showing posts from August, 2013

Kenka Matsuri II

Image
Kenka Matsturi - the Battle Festival, Himeji, Japan. ©2012 Darren DeRidder

Testing Express.JS REST APIs with Mocha

My post on Testing REST APIs with RESTClient and Selenium IDE has been getting some attention, but you might also want an automated testing solution to be part of your build process.

This post will cover testing REST API's built with Express.JS, using Mocha as the test framework. Express and Mocha are both by the same author and work well together.  This technique can also be used to test Express apps in general.

In a nutshell, we'll create a test suite in Mocha that does the following:
instantiates and runs our REST API server (an Express app)sends HTTP (or HTTPS) requests to the REST APIchecks the responses for appropriate values So, let's say you've written an Express app that works as a REST API server, and now you want to automatically test it over HTTP. Assuming you have Mocha installed, and are somewhat familiar with how to use it, building a suite to test your Express app over HTTP is relatively simple.

Our example test suite is a file located at test/app_test.j…