12 Testing and validating APIs
This chapter covers
- Generating automatic tests for REST APIs using Dredd and schemathesis
- Writing Dredd hooks to customize the behavior of your Dredd test suite
- Using property-based testing to test APIs
- Leveraging OpenAPI links to enhance your schemathesis test suite
- Testing GraphQL APIs with schemathesis
- Automatically generating tests for GraphQL mutations
This chapter teaches you how to test and validate API implementations. Up to this point, we’ve learned to design and build APIs to drive integrations between microservices. Along the way, we did some manual tests to ensure our implementations exhibited the correct behavior. However, those tests were minimal, and most importantly, they were purely manual and therefore not repeatable in an automated fashion.
In this chapter, we’ll learn to run an exhaustive test suite against our API implementations using tools such as Dredd and schemathesis. Dredd and schemathesis are tools for API testing, and they’re part of the toolkit of every API developer. Both Dredd and schemathesis work by looking at the API specification and automatically generating tests against our API server. As an API developer, this is very neat, because it means you can focus your efforts on building your APIs instead of testing them.