HomeGuides › API testing in CI/CD

API testing in CI/CD: gate every deploy

By the Flasqo team · Updated 24 August 2026

In short

Place tests by speed and blast radius: functional and contract on every pull request, regression on merge, smoke after deploy, performance on a schedule. Keep the pull-request stage under ten minutes.

  • Place tests by speed and blast radius: functional and contract on every pull request, regression on merge, smoke after deploy, performance on a schedule.
  • Keep the pull-request stage under ten minutes. Past that, developers context-switch and the feedback loop stops working.
  • Block on functional, contract and smoke failures. Express performance as a budget with a threshold rather than a hard gate.
  • Inject credentials as masked CI secrets tied to a least-privilege test account.

Which tests belong at which stage

The organising principle is that fast, deterministic tests run often, and slow or noisy ones run on a schedule. Putting a 40-minute load test on the pull-request path guarantees it gets disabled.

StageTestsBudgetOn failure
Pull requestFunctional, contract< 5 minBlock merge
Merge to mainRegression, integration< 15 minBlock deploy
Post-deploySmoke against the real environment< 2 minRoll back
NightlyLoad, fuzz, securityHoursAlert, don't block
ScheduledChaos experimentsVariesInvestigate

Keeping the pipeline under ten minutes

Ten minutes is roughly the limit of a developer's willingness to wait. Beyond it they start another task, and the feedback loop that makes CI valuable is broken.

Post-deploy smoke tests

The tests that ran before deployment validated a build artefact. They said nothing about whether the deployment itself succeeded — whether configuration was applied, migrations ran, secrets resolved and the load balancer picked up the new instances.

A post-deploy smoke suite hitting the real environment is the only thing that verifies this, and it should be small enough to complete in under two minutes: authenticate, read the primary resource, exercise one write path, check the health endpoint. Wire its failure to an automatic rollback, and a bad deploy is reverted before most users encounter it.

Handling secrets

Treat a leaked test token as a production incident. Attackers scan public repositories continuously, and a credential in a public commit is typically exercised within minutes of being pushed.

Blocking versus warning

A gate that blocks too aggressively gets bypassed; one that never blocks is decoration. The distinction that works in practice is determinism:

For performance, express the rule as a budget against a rolling baseline — for instance, fail when p95 latency regresses more than 20% against the previous release. That catches genuine regressions without halting delivery on noise.

A worked example

A typical GitHub Actions arrangement:

on:
  pull_request:          # functional + contract, 4 shards, ~4 min
  push:
    branches: [main]     # + regression and integration, ~12 min
  deployment_status:     # smoke against the deployed environment, ~90s
  schedule:
    - cron: '0 2 * * *'  # nightly load, fuzz and security

The pull-request job needs only a staging base URL and a masked test-account token. The post-deploy job reads the environment URL from the deployment event, so the same workflow validates every environment without duplication.

Test your API without writing the tests

Paste a URL. Flasqo discovers your endpoints, generates the suite and runs it — free, no credit card.

Start testing free

Frequently asked questions

Which API tests belong in a CI pipeline?

On every pull request run functional and contract tests, targeting under five minutes. On merge to the main branch add regression and integration suites. Post-deploy run smoke tests against the real environment. Load, chaos and fuzz suites run nightly or on a schedule, because they are too slow to gate a commit.

How long should an API test pipeline take?

Keep the pull-request stage under ten minutes; beyond that, developers start context-switching and reviewing code before results land. Achieve it by running tests in parallel, sharding by endpoint, and moving slow performance suites off the commit path.

Should a failing API test block a deploy?

Yes for functional, contract and smoke failures — those indicate real breakage. Performance results are better expressed as a budget with a threshold, for example failing the build only when p95 latency regresses more than 20% against the previous baseline, so ordinary noise does not halt delivery.

How do you test APIs that need secrets in CI?

Inject credentials as masked CI secrets and never commit them. Use a dedicated test account with least privilege, rotate its token on a schedule, and point tests at a staging environment. If tests must run against production, restrict them to read-only smoke checks.

Related reading

API Testing: The Complete Guide API Chaos Testing: Resilience Testing With Fault Injection API Contract Testing: Stop Breaking Your Consumers GraphQL API Testing: Queries, N+1 & Depth Limits API Smoke Testing: Fast Health Checks for Critical Endpoints API Regression Testing: Prevent Breaking Changes in Production API Fuzz Testing: Break It Before Attackers Do Flasqo vs Hoppscotch Flasqo vs Katalon Flasqo vs JMeter Flasqo vs k6