API Testing With Cucumber

An API represents a set of rules that enables services to communicate with each other. It is important to have a shared understanding of the API by the stakeholders. Behavior Driven Development (BDD) allows us to describe behaviors that are understandable to domain experts, testers, and developers through examples. A well-written example serves to represent a balanced view of competing concerns -

  • Shared understanding. An example can be shared among API stakeholders to promote communication and understanding.
  • Tests.  Implement the example as an automated test to check the functionality of the API.
  • Documentation. An example can be used by anyone to understand the system.

BDD is a very apt tool to test APIs. We will use Cucumber that supports BDD to test APIs developed in Java. One advantage of doing so is that the Java developer who implemented the API does not have to learn a new language to test it.