Skip to main content

Claude Prompt to Build an API Integration Test Suite

Generate integration tests for REST or GraphQL APIs with auth, validation, authorization, database-state assertions, and contract checks.

Vul de plaatshouders in

Edit the values, then copy your finished prompt.

Jouw Prompt
prompt.txt

                                

What this prompt does

This prompt builds an integration test suite for an API. You specify [api_type] (REST or GraphQL), the [framework], and a list of [endpoints], and for each endpoint the AI generates a battery of tests: authentication cases (valid, expired, missing token), happy path, validation errors, authorization checks, database-state assertions, response-structure validation against a [schema_format] schema, pagination and filtering where relevant, and rate-limit behaviour. It uses [test_framework] with your [db_strategy].

The structure works because it tests at the seam where most real bugs live — the boundary between client input and persisted state. By requiring auth, validation, authorization, and database assertions for every endpoint, the prompt catches the authorization and boundary defects that are expensive to find in production. The [db_strategy] variable ensures tests start from a known state, and schema validation against [schema_format] keeps response contracts honest.

When to use it

  • You run an API-first backend and want auth, validation, and DB state locked down before launch.
  • You are adding new [endpoints] and want them covered consistently.
  • You need authorization and role-based access tested, not just happy paths.
  • You want responses validated against your [schema_format] contract.
  • You need database-state assertions confirming records are actually created, updated, or deleted.
  • You want pagination, filtering, and rate-limit behaviour exercised.

Example output

You get a [test_framework] test suite organised by endpoint. Each [endpoints] entry gets multiple test methods — auth variants, valid and invalid inputs, authorization checks, and assertions on database rows — plus shared helpers for authentication and factory data. With a [db_strategy] like RefreshDatabase, each test runs against a clean schema.

Pro tips

  • List [endpoints] with their HTTP verbs and paths exactly; precise input yields precise tests.
  • Match [db_strategy] to your project so tests reset state the way the rest of your suite expects.
  • Make sure the [framework] and [test_framework] pairing is real — Laravel with PHPUnit, Express with Jest — or generated helpers will not run.
  • Provide your [schema_format] spec if you have one; structure assertions are far stronger when grounded in a real OpenAPI or JSON Schema definition.
  • Verify the authorization tests use roles that actually exist in your app.
  • Run the suite against a seeded test database first to catch factory mismatches early.

Frequently Asked Questions

Does this support GraphQL as well as REST?
Yes. Set `[api_type]` to GraphQL and the prompt adapts to query and mutation testing instead of REST verbs. The auth, validation, and authorization checks still apply, though the request shape and schema assertions differ from a REST suite.
How does it verify the database actually changed?
The prompt requires database-state assertions per endpoint, so generated tests check that records are created, updated, or deleted as expected. With a `[db_strategy]` like RefreshDatabase, each test starts clean, making those assertions reliable and isolated.
Will the validation tests cover edge cases?
They cover missing required fields, invalid types, and boundary values by design. Whether they cover every edge case depends on how completely you describe `[endpoints]`. Review the generated cases and add any domain-specific boundaries the model could not infer.
Can it validate responses against my OpenAPI spec?
Yes. Set `[schema_format]` to OpenAPI 3.0 or your schema format and the tests assert response structure against it. Providing the actual spec produces stronger contract checks than relying on the model to guess your response shape.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Meer in Testing & QA Automation Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support