Mid-LevelAPI & Integration Testing
How do you handle API test data setup and teardown?
- test data
- setup/teardown
- test isolation
Answer it first, then compare. Nothing here is saved or scored.
Model answer
Setup: create test data via API calls (POST endpoints) before each test, don't rely on pre-existing data. Teardown: delete created data after each test. Use unique identifiers (UUIDs, timestamps) to avoid conflicts in parallel runs. For complex scenarios, use database seeding or transaction rollbacks. In frameworks like Playwright, use `beforeAll`/`afterAll` for shared setup and `beforeEach`/`afterEach` for test-specific data.
What interviewers listen for
- Schema-first thinkingYou validate response shape before you assert on values, every time.
- Status-code literacyYou can defend why 401 vs 403 vs 422 matters for the consumer.
- Contract awarenessYou know when consumer-driven contract tests beat end-to-end checks.
- Auth fluencyYou can describe rotating tokens across parallel workers without secrets in logs.