Introducing Bat: Behavioral API Tester
Tags: javascript, api, testing, cucumber
Published: 2019-08-28 13:42:56

---
title: Introducing Bat: Behavioral API Tester
published: true
description: Bat is a tool to help you write runnable specifications for HTTP APIs, such as REST, RPC and GraphQL, in readable English
tags: javascript, api, testing, cucumber
cover_image: https://thepracticaldev.s3.amazonaws.com/i/oru3cgodydgmv213ummt.png
canonical_url: https://medium.com/harver-engineering/introducing-bat-behavioral-api-tester-c630499602c3
---

I work at [Harver](https://careers.harver.com/) where we have several mission critical, customer facing HTTP/Rest APIs built with Node.JS. When I joined, last year, the standard procedure to support developing and testing these APIs was to use Postman. But the process of integrating Postman with version control, writing Javascript tests with Postman's GUI and integrating into CI with Newman did not represent a particularly great developer experience to me. I wanted to find a way to improve upon this.

I have always been a fan of [Cucumber](https://cucumber.io/), a tool for writing runnable software specifications in readable business language, and, in general, a Behavior Driven Development (BDD) approach to development. It occurred to me that Cucumber might be a great fit for developing and testing our HTTP APIs too.

From here, together with my colleagues at Harver, we created [Bat (Behavioral API Tester)](https://github.com/harver-engineering/bat); a tool to help write runnable specifications for HTTP APIs, such as Rest, RPC and GraphQL, in readable English. Such specs can then be easily automated and integrated into your continuous integration pipeline. It runs on Node.JS and is based on [Cucumber.JS](https://github.com/cucumber/cucumber-js).

It works well for API testing with Cucumber because, within reason, there are a finite number of actions and assertions associated with testing an HTTP API. Bat builds upon Gherkin to create a common vocabulary (a DSL) for describing HTTP interactions. When taking a BDD approach to API development, such specifications provide a great way to write and review your intentions before writing any implementation code. For example:

![Alt Text](https://thepracticaldev.s3.amazonaws.com/i/oru3cgodydgmv213ummt.png)

The full set of step definitions is [documented here](https://github.com/harver-engineering/bat/blob/master/docs/step-reference.md). We’ve also provided (and will continue to add) a bunch of [examples in the repo](https://github.com/harver-engineering/bat/tree/master/examples).

Because Bat is essentially a plugin for Cucumber.JS, it’s easy to extend with custom step definitions. We most often do this at Harver for non-standard stuff related to setting up the context (`Given` steps), such as custom authentication procedures or setting up test data. Internally, it uses [SuperAgent](https://visionmedia.github.io/superagent/) as an HTTP client and to maintain sessions.

Bat has more useful features for making it usable in the real world such as variable replacement, compatibility with Postman’s environment file format and integration points with Open API specifications. See the [Readme](https://github.com/harver-engineering/bat/blob/master/README.md) for more details.

Now Bat is [open-source on Github](https://github.com/harver-engineering/bat) and it is used by a broader audience, more missing features will become apparent. So please [raise issues](https://github.com/harver-engineering/bat/issues) to request new features and raise bugs. If you want to contribute back to Bat, please check the [Contributing Guide](https://github.com/harver-engineering/bat/blob/master/CONTRIBUTING.md).