Imagine this: Your development team releases API v2. Everything looks perfect. New features work, tests pass, and the deployment is successful.
But the next morning, users of your existing mobile application start reporting errors.
What happened?
The problem might be a breaking API change.
Perhaps a response field was renamed, a data type changed, or a previously optional field became mandatory. Your new API version works, but existing consumers are no longer compatible.
This is one of the biggest challenges in modern API development.
Building a new API version is easy. Making sure the old versions continue working is the real challenge.
That's where API Versioning Testing comes in.
In this article, we'll explore API versioning strategies, backward compatibility, practical test scenarios, automation examples, and how to integrate version checks into CI/CD pipelines.
Want the complete technical guide? Read API Versioning Testing: Backward Compatibility Checks in CI – TotalShiftLeft.
- What Is API Versioning Testing?
API versioning testing is the process of verifying that existing API consumers continue working correctly when a new API version is introduced.
Consider an e-commerce application.
Your existing API returns:
API v1
{ "orderId": 101, "customerName": "John", "total": 250 } Your development team introduces API v2:
API v2
{ "orderId": 101, "customer": { "name": "John" }, "amount": { "value": 250 } } The new response structure might be better designed, but what happens to applications that still expect customerName and total?
They may break!
API versioning testing helps identify these compatibility problems before deployment.
Its main objectives include:
- Maintaining backward compatibility.
- Detecting breaking changes.
- Validating multiple API versions.
- Protecting existing consumers.
- Preventing unexpected production failures.
- Understanding Different API Versioning Strategies
There are several ways to manage API versions. Your testing strategy should match the versioning approach used by your application.
A. URI Path Versioning
This is one of the most common approaches.
GET /api/v1/orders/101 GET /api/v2/orders/101 Each version has a separate URL path.
What should you test?
- Does v1 continue returning the expected response?
- Does v2 return the new response structure?
- Are both versions accessible?
- Does an unsupported version return the documented error?
B. Query Parameter Versioning
The version is passed through a query parameter.
GET /api/orders/101?api-version=1 Test scenarios:
- Valid version parameter.
- Missing version parameter.
- Unsupported version.
- Default version behavior.
- Invalid version format.
C. Header-Based Versioning
The version is included in a custom request header.
GET /api/orders/101 Api-Version: 2 Test scenarios:
- Valid version header.
- Missing version header.
- Invalid version header.
- Correct response for each version.
- Appropriate cache variation using
Vary: Api-Version.
D. Media Type Versioning
The client specifies the required version using the Accept header.
Accept: application/vnd.example.order.v2+json Verify that the server returns the correct representation and handles unsupported media types appropriately, such as with 406 Not Acceptable.
Pro Tip: Whatever strategy you choose, test unsupported versions explicitly. An API should never silently return an unintended version.
- Breaking vs. Non-Breaking API Changes
Not every API change requires a new major version.
Understanding the difference between breaking and non-breaking changes is essential for API testers.
Consider these examples:
| API Change | Compatibility |
|---|---|
| Adding an optional request field | Usually non-breaking |
| Adding a new endpoint | Usually non-breaking |
| Removing an existing endpoint | Breaking |
| Renaming a response field | Breaking |
| Changing string to integer | Breaking |
| Making an optional request field mandatory | Breaking |
| Removing an enum value | Breaking |
| Changing default sorting behavior | Potentially breaking |
One interesting case is adding a new response field.
It is generally safe for tolerant consumers that ignore unknown fields. However, strict clients that reject additional properties may fail.
Similarly, adding a new enum value can break consumers that only recognize a predefined set of values.
The important lesson: A change that looks harmless to the API developer may be breaking for the application consuming the API.
- Five Essential API Versioning Test Scenarios
Let's explore practical examples using an Orders API.
Test Case 1: Verify Old API Version
Request:
GET /api/v1/orders/101 Expected result:
- Status code:
200 OK. - Existing response fields remain available.
- Data types remain unchanged.
- Business behavior matches the v1 contract.
This ensures existing applications continue working.
Test Case 2: Verify New API Version
Request:
GET /api/v2/orders/101 Expected result:
- Status code:
200 OK. - New response structure is correct.
- New fields follow the v2 specification.
- Business rules are correctly implemented.
Test Case 3: Test Unsupported API Version
Request:
GET /api/v9/orders/101 Expected result:
404 Not Found The API should return a clear error rather than silently falling back to the latest version.
The exact error status should follow your API's documented behavior.
Test Case 4: Verify Backward Compatibility
Call both versions:
GET /api/v1/orders/101 GET /api/v2/orders/101 Compare shared business information.
For example:
- Order ID should match.
- Customer identity should match.
- Total amount should match.
- Business status should remain consistent.
The response structure may differ, but shared business meaning should remain correct.
Test Case 5: Verify Deprecated API Version
Suppose v1 is scheduled for retirement.
Check whether the API communicates the deprecation information through response headers.
For example:
Deprecation: @1767225600 Sunset: Fri, 31 Dec 2027 23:59:59 GMT Also verify that the API provides documentation or a link to the successor version when configured.
A deprecated version should continue behaving as documented until it is retired.
- Automate API Version Testing Using Python and Pytest
Manual validation is useful, but maintaining several API versions requires automation.
Let's look at a simple example.
Imagine you have two API versions:
- v1:
/api/v1/orders/101 - v2:
/api/v2/orders/101
You want to verify that both versions return successful responses.
import pytest import requests BASE_URL = "https://api.example.com" @pytest.mark.parametrize("version", ["v1", "v2"]) def test_supported_api_versions(version): url = f"{BASE_URL}/api/{version}/orders/101" response = requests.get(url, timeout=10) assert response.status_code == 200 data = response.json() assert "orderId" in data This test checks whether both versions are accessible and return the required order ID.
Validate the v1 Response Schema
You can also validate the response against a version-specific JSON schema.
import json import requests from jsonschema import Draft202012Validator def test_v1_order_schema(): response = requests.get( "https://api.example.com/api/v1/orders/101", timeout=10 ) assert response.status_code == 200 schema = json.load( open("schemas/order.v1.json") ) errors = list( Draft202012Validator(schema).iter_errors( response.json() ) ) assert not errors, [ error.message for error in errors ] Important: Keep the released v1 schema frozen. Do not update it simply to make a failing compatibility test pass. Otherwise, you may hide the very breaking change you're trying to detect.
- How to Detect Breaking Changes Automatically With OpenAPI
Imagine a developer changes an API specification.
How can your QA team identify whether the change breaks existing consumers before the application is deployed?
This is where OpenAPI specification comparison becomes valuable.
Two useful tools are:
- oasdiff
- OpenAPITools openapi-diff
For example, using oasdiff:
docker run --rm \ -v "$PWD:/specs" \ tufin/oasdiff \ breaking /specs/base.yaml \ /specs/openapi.yaml \ --fail-on ERR Here:
-
base.yamlrepresents the last released API specification. -
openapi.yamlrepresents the updated specification. - The tool identifies potentially breaking changes.
- CI can fail when breaking changes are detected.
Why is this useful?
Because teams can catch issues during code review rather than discovering them after deployment.
A critical best practice: Compare against the last released specification, not merely the previous commit. Breaking changes can be introduced across multiple pull requests.
- Consumer-Driven Contract Testing: Protect the Applications Using Your API
An API provider may believe a change is safe.
But do the applications consuming that API agree?
For example:
Your Orders API has three consumers:
- Web application.
- Android application.
- Third-party payment service.
Each consumer may depend on different fields and behaviors.
Consumer-driven contract testing helps verify that the API continues satisfying the expectations of its consumers.
One popular tool is Pact.
A typical workflow looks like this:
- Consumers define their API expectations.
- Consumer contracts are published.
- The API provider verifies those contracts.
- Verification results are checked during CI/CD.
- Deployment is allowed only when the required consumer contracts pass.
This approach is particularly valuable in microservices architectures where independent teams deploy services frequently.
- Integrate API Version Testing Into Your CI/CD Pipeline
Testing API versions manually before every release is not scalable.
Instead, make backward compatibility a part of your automated development workflow.
A practical pipeline can look like this:
Step 1: Developer updates the API specification.
Step 2: CI retrieves the last released OpenAPI specification.
Step 3: A breaking-change detection tool compares both specifications.
Step 4: Tests execute for every supported API version.
Step 5: Consumer contract verification runs.
Step 6: Deprecation and sunset behavior is validated.
Step 7: The pipeline reports failures and blocks deployment when required quality gates fail.
The biggest advantage?
Teams discover compatibility issues before they reach production.
This is the real value of shift-left API testing.
- Common API Versioning Testing Mistakes
Even experienced engineering teams can make mistakes when managing API versions.
Watch out for these:
- Testing only the latest API version
A new release can accidentally break older versions through shared backend code.
- Updating old schemas to match new behavior
This hides backward-compatibility issues. Preserve historical schemas.
- Ignoring behavioral changes
A change to default sorting, pagination, rounding, or error formats can break consumers even when the OpenAPI structure remains unchanged.
- Not testing unsupported versions
An unknown version should produce a clear, documented response.
- Creating unnecessary API versions
Not every additive change requires a new major version. Excessive versioning increases maintenance and testing complexity.
- Forgetting consumer contracts
An API may pass its own tests but still break an application that depends on undocumented or strict behavior.
- Can AI Improve API Versioning Testing?
As API architectures become more complex, manually identifying and validating every change becomes increasingly difficult.
AI-powered API testing can help teams:
- Generate tests from OpenAPI specifications.
- Identify potential breaking changes.
- Suggest additional test scenarios.
- Improve test coverage.
- Automate repetitive validation.
- Support continuous API quality checks.
At TotalShiftLeft, we're focused on helping developers and QA teams identify API issues earlier through AI-powered API test generation, automated testing, and shift-left quality practices.
The goal is to make API quality a continuous process rather than something teams check only before release.
Final Thoughts: Never Let a New API Version Break Existing Consumers!
API versioning is not simply about creating /v1, /v2, or /v3 endpoints.
It's about maintaining trust with every application, service, and customer that depends on your API.
Before releasing a new version, make sure you:
✅ Test every supported API version.
✅ Validate backward compatibility.
✅ Compare OpenAPI specifications.
✅ Verify consumer contracts.
✅ Check deprecated and unsupported versions.
✅ Automate compatibility checks in CI/CD.
Remember: A successful new API release should not become an unexpected failure for existing consumers.
Want to Go Deeper Into API Versioning Testing?
We've published a detailed technical guide covering backward compatibility checks, API versioning strategies, OpenAPI diff tools, Pytest automation, consumer contracts, and CI/CD integration.
Read the complete guide here: API Versioning Testing: Backward Compatibility Checks in CI – TotalShiftLeft.
Build APIs that evolve without breaking trust. Test smarter. Shift quality left!
About TotalShiftLeft
TotalShiftLeft is an AI-powered shift-left API testing platform that helps developers and QA teams generate API tests, identify bugs early, automate testing in CI/CD pipelines, and improve API quality throughout the development lifecycle.
