Behaviour-Driven Development (BDD) is an improvement over Test-Driven Development, but in more of a social manner rather than in strictly technical terms. Specifically, it enriches the description of how a system should behave under testing by using language that is accessible to all stakeholders. If you want learn the reasoning that led to BDD Dan North, the developer, offers what led to his discovery.

The catalyst for my use of BDD was a requirement to test a REST api that was being used by a number of clients including an Angular web app, an IOS app and an Android app.

The REST api itself was implemented in Drupal (PHP) but being REST (via HTTP) it was agnostic as to the programming language (as I am) used for testing. Initially I attempted to use a combination of JUnit along with the Apache Commons HttpClient library but this proved cumbersome; hiding what was being tested behind the supporting code. I then explored several BDD tools before settling on Rest-assured. I like it because in is mature, has an active code-base and a nice DSL (quite a feat since it is written in Java!).

The usage guide will get you up and running so I will go straight into code since I assume that is why you are here. This particular example solution deals with the common case of needing a user to be logged in to perform certain tests, logout for instance. In Rest-assured Filters can be used to realize this need.

A helper class TestFixtures is used to intialize a new filter instance by reading in user login username and password etc from a config file (yml). This can be used directly in code but this makes changes easier.

If the above code is successful then the filter is ready for use. I am using rest-assured outside of a test here because it is so awesome. But now I have to manually check for an invalid HTTP status code :(.