Criteria for API Automation
Factors to Evaluate Before Automating
- Stability: is the API's contract (endpoints, request/response format) reasonably finalized?
- Reusability: will the test be run repeatedly across multiple builds or releases?
- Complexity: does the scenario involve enough logic (data validation, multiple steps) to justify scripting?
- Business criticality: is the endpoint core to the application's functionality?
- Team skill: does the team have the scripting skills needed to build and maintain the automation?
Scoring Candidates Before You Write Code
A simple way to apply the factors is to score each API scenario from 1 (low) to 3 (high) on every criterion and add the results. The total is not exact science, but it turns a vague discussion into a clear ranked list.
| Scenario | Stability | Reuse | Complexity | Criticality | Total |
|---|---|---|---|---|---|
| POST /login | 3 | 3 | 2 | 3 | 11 |
| POST /orders with stock check | 2 | 3 | 3 | 3 | 11 |
| GET /reports/beta (still changing) | 1 | 2 | 2 | 1 | 6 |
| One-time data migration endpoint | 2 | 1 | 1 | 2 | 6 |
The login and order endpoints go into the first automation sprint. The beta report waits until its contract settles, and the migration endpoint is checked manually because it will only run once.
Signs a Scenario Should Stay Manual for Now
- The response format changes almost daily during early development.
- The check is run once, for example during a one-off data fix.
- The result needs human judgement, such as reviewing the wording of generated text.
- Test data cannot be created or reset reliably, so every run would need manual preparation.
- The cost of building and maintaining the script is clearly higher than running it by hand a few times.
"Manual for now" is not "manual forever". Revisit these items once the API stabilises or starts being used by more consumers.
Prerequisites for Reliable API Automation
Even a perfect candidate fails as automation if the basics are missing. Before scripting, confirm the following:
- A documented contract, such as an OpenAPI specification, describing endpoints, fields and error codes.
- A dedicated test environment whose data is not changed by other teams during runs.
- Test data strategy: create data through the API itself in setup steps, and clean it up afterwards.
- Authentication handling: a way to obtain tokens for test users without hardcoding secrets in the code.
- CI integration, so tests run on every build and failures are visible to the whole team.
What a Good Automated API Check Covers
Once a scenario is chosen, aim for more than a single "status 200" assertion. A useful test usually verifies the status code, the response schema, key field values, important headers and a reasonable response time agreed with the team. It also includes negative cases: missing fields, invalid tokens, wrong data types and requests for records that do not exist.
API tests sit in the middle of the testing pyramid. They are faster and more stable than UI tests and catch integration problems that unit tests miss, which is why many teams automate them before investing heavily in UI automation.
Common mistakes: automating everything at once, chaining tests so one failure breaks the rest, relying on shared data that changes between runs, and never deleting tests for endpoints that were retired.
Ready to master real-world software testing?
Learn manual and automation testing hands-on with mentor-led sessions.