Skip to main content
Cleanup tab — DELETE chains and per-resource status

What Auto Cleanup Does

Every API test run creates real records in your test environment: users, orders, sessions, files. Left behind, they break later runs:
Auto Cleanup runs after every test run, whether tests passed or failed, and removes the records that run created. There’s nothing to configure. TestSprite issues the DELETE calls in dependency order, children first and then parents (orders before the user they belong to), so each run starts from the same empty state. This matters most for scheduled runs and CI, where leftovers pile up fast. Which records count is decided by their dynamic variables: handles to created resources, like an order_id, get cleaned up; plain values, like a total_amount, don’t.

The Cleanup Tab

Open Test Runs → a run → Cleanup to see what was deleted (or attempted) after that run. Captured resources show as cards in two sections: Each card shows: A progress bar at the top summarizes how many captured resources have been cleaned up.

When Cleanup Runs

Once all endpoint and integration tests finish, TestSprite issues the DELETE calls. Cleanup usually takes 5–60 seconds depending on resource count. The dashboard stays usable meanwhile, but the run isn’t fully done until cleanup finishes.

When Cleanup Fails

To retry, rerun the failing cleanup test from its detail page, or Re-run all. Every rerun runs Auto Cleanup again at the end.

Manual Cleanup

If a resource couldn’t be auto-cleaned (no matching DELETE endpoint was discovered), it appears under Might be orphaned with its ID and source endpoint. You can:
  1. Add a DELETE endpoint to discovery: re-run API Discovery once your DELETE endpoints are reachable
  2. Delete it yourself with your own backend tooling
To keep certain records, opt them out in chat: “Don’t auto-clean up the records created by POST /audit-logs; they need to stay for audit retention”.

Edge Cases & Troubleshooting

Most likely causes:
  • No DELETE endpoint discovered: shown under “Might be orphaned”. Add the endpoint manually on the configuration step (or in a new project) so cleanup has a verb to invoke.
  • DELETE endpoint failed with 4xx: the cleanup test shows Failed with the response body. Often an auth or permission issue with the test account.
  • Deeply nested children (4+ levels) can need a hint. Refine in chat: “DELETE /comments must run before DELETE /posts must run before DELETE /users”.
Refine: “Don’t auto-clean up the seed-data user system@testsprite.com”. TestSprite will skip cleanup for resources matching that filter.
  • Many resources: 1000+ created records means 1000+ DELETE calls. Prune the plan to create less, or accept the cost.
  • Slow DELETE endpoint: if each DELETE takes 5+ seconds, investigate on your API side.
  • Many retries: check the Cleanup tab for the failure pattern.
  • The run must be finished (tests Passed or Failed, none Running). Cleanup starts after the run completes.
  • At least one cleanup-relevant record must exist. If your tests don’t produce record IDs, there’s nothing to clean up.
Cleanup issues DELETEs in parallel for resources of the same type. If your API rate-limits DELETE, refine: “Issue cleanup DELETEs serially, not in parallel”.

Where to Go Next

Dynamic Variables

See which test deleted each captured value, next to where it came from

Dependency Chains

How run order is determined

Auto-Auth

Keeps auth alive across long-running cleanups