I have always been a fan of Cucumber, 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); 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.
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:
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 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 for more details.
Now Bat is open-source on Github and it is used by a broader audience, more missing features will become apparent. So please raise issues to request new features and raise bugs. If you want to contribute back to Bat, please check the Contributing Guide.