Module 06: API Testing and Contract Testing¶
← End-to-End Testing | Topic Home | Next → Test-Driven Development
REST API testing with httpx and Requests; consumer-driven contract testing with Pact; OpenAPI response validation; Newman for Postman collection automation.
Overview¶
This module is a stub. Content will be added in a future iteration.
Topics covered in this module:
- REST API testing strategies — testing HTTP methods, status codes, headers, and response bodies
- Python API testing with
httpx— async test client, response assertions, auth headers - Consumer-driven contract testing with Pact — the consumer/provider model, writing consumer tests, provider verification
- OpenAPI validation — using
openapi-coreorschemathesisto validate responses against an OpenAPI spec - Newman — running Postman collections from the command line in CI
- Testing authentication — JWT tokens, API keys, OAuth flows in integration tests
- GraphQL testing — query testing, mutation testing, schema validation
- Fuzz testing APIs — using Schemathesis to generate adversarial inputs automatically
Prerequisites¶
- Module 04: Integration Testing in this topic
- Basic understanding of REST APIs — HTTP methods, status codes, JSON
Objectives¶
By the end of this module, you will be able to:
- Write HTTP-level integration tests for a REST API using
httpxorsupertest - Implement consumer-driven contract tests with Pact to verify service compatibility
- Validate API responses against an OpenAPI specification
- Identify the scenarios where contract testing provides more value than full integration tests
- Run Postman collections in CI using Newman
Cross-Links¶
- [[qa-testing/modules/04_integration-testing]] — API testing is a specialized form of integration testing
- [[django-fastapi-flask]] — FastAPI generates OpenAPI specs automatically; this module's validation techniques apply directly
- [[qa-testing/glossary#contract-test]] — Formal definition of contract tests