If you search on the internet for unexpected API behavior, you’ll soon discover that no one likes when an API doesn’t work as expected. When you take into account the increasing number of APIs and continuous development and delivery of the services built on top of them, it’s no surprise that APIs can move away from their initially expected behavior. This is why expanding API test coverage is critical for success. For years, we have created unit and functional tests for our APIs, but where do we go from there?
Taylor Barnett explains how to contract test APIs (i.e, writing tests to ensure that an API or microservice works as described in an agreement) based on a single source of truth—in this case, an OpenAPI Specification document. Contract testing is useful for testing the accuracy of API implementations in server code, SDKs, client libraries, and even third-party APIs, which is especially helpful when other services rely on an API.
Taylor details the differences between testing an SDK and the implementation of an API and other use cases and outlines how contract testing can lead to faster development, fewer breaking code changes, and more accurate implementations. Along the way, she shares real-life contract testing examples and techniques to implement within your API projects.