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.
Taylor Barnett is the lead community engineer at Stoplight. Taylor is passionate about building great developer experiences within APIs with an emphasis on empathy and inclusion within documentation, SDKs, support, and other community-focused projects. Previously, she was the lead community engineer at data analytics API company Keen IO. Taylor has spoken about developer experience, SDKs, inclusion, and building developer communities, including open source communities, at conferences such as O’Reilly OSCON, API Strategy & Practice, AlterConf, Hackcon, and local meetups. In her free time, she helps organize Women Who Code Austin, advises developer communities, drinks sour beers, and climbs in Austin, Texas.
©2018, O'Reilly Media, Inc. • (800) 889-8969 or (707) 827-7019 • Monday-Friday 7:30am-5pm PT • All trademarks and registered trademarks appearing on oreilly.com are the property of their respective owners. • firstname.lastname@example.org