DevNet Associate (DEVASC) v1.0Understanding and Using APIsMedium

A network automation engineer is building a CI/CD pipeline. They need to ensure that changes to an API client application are compatible with the API's latest specification before deploying. This involves validating that the client sends requests and handles responses according to the API's contract. Which type of testing is best suited for this purpose?

  1. AUnit Testing
  2. BIntegration Testing
  3. CContract Testing
  4. DEnd-to-End Testing
Show answer & explanation

Correct answer: C. Contract Testing

Contract testing specifically validates that a client and a service (API) adhere to a shared understanding (contract) of how they communicate. It ensures compatibility by verifying request and response formats, data types, and expected behaviors without needing full end-to-end integration.

Why the other options are wrong

  • A. Unit testing focuses on individual components in isolation, not their interaction with external APIs.
  • B. Integration testing verifies interactions between multiple components, but contract testing is more specific to API compatibility based on a defined contract.
  • D. End-to-end testing verifies the entire system flow, which is typically more complex and slower than contract testing for compatibility checks.

API Contract Testing

A form of testing that ensures that two communicating systems (e.g., an API client and an API service) adhere to a predefined contract regarding their interaction, including request/response formats and data types.

  • Verifies compatibility between API client and service.
  • Based on a shared 'contract' (e.g., OpenAPI specification).
  • Faster and more isolated than full integration tests.
  • Prevents breaking changes from being deployed.

Memory trick: Contract ensures client and API Connect Reliably.

More Understanding and Using APIs questions