AI-POWERED TESTING

Using AI Chat to Understand an Unfamiliar API Before Testing

Every tester has been handed an API they've never seen and told to "get some tests in place". Maybe there's an OpenAPI spec that's a few versions behind, maybe there's no documentation at all, or maybe the docs exist but don't say what the error codes mean in practice. Before I write a single assertion I need a mental model of the API: its shape, its auth, its quirks. AI chat has become my first stop for building that model quickly.

This isn't about generating tests blindly. It's about using a conversation to compress the reading, trial-and-error requests and questions to the dev team into a focused session. I treat the assistant as a well-read colleague I can ask anything, including "what's the difference between a 400 and a 422 here?" But I also treat everything it says as a claim, not a fact. It will describe behaviour that isn't in the spec, confidently, in the same tone it uses for things that are.

So my recon has two halves. The chat builds the map, then I check the map against the real API, by hand, with a small set of executable checks, or with an agent exploring a sandbox under strict rules. Here's how each step works.

Build an API Automation Framework in Python

Learn Python, Behave, GitHub Copilot, APIs, and CI/CD by building a real framework you can finish in a weekend.

Learn more

Feed it the contract, then ask about failure

I start with whatever contract material exists (an OpenAPI file, a Postman collection, even a curl example from a README) and paste it into the chat. Before pasting, I remove anything sensitive: real tokens, internal hostnames, customer data in example payloads. Then I ask a specific question rather than "explain this API":

For POST /orders in the spec above:
1. List required and optional fields with types.
2. For each required field, what does the spec say happens if it is missing or the wrong type?
3. Quote the part of the spec each answer comes from.
4. Mark anything you are inferring rather than reading from the spec as INFERRED.

Points 3 and 4 do most of the work. Asking for quotes ties answers to the document, and the INFERRED label separates what the spec says from what the model expects APIs like this to do. Both are useful, but only one is evidence. The inferred items are often the most interesting, because they're the questions to put to the developers or check against the sandbox. Missing-field behaviour is where many real bugs live, as I cover in writing API tests that catch missing fields before prod does.

Decode the auth flow before touching test code

Authentication is where unfamiliar APIs hurt testers most. If you get the token flow, key placement or expiry wrong, every test fails for the wrong reason. I paste the auth section of the docs and ask for the exact sequence of requests to get a valid token, the headers every later request needs, and how expiry and refresh work. Then a follow-up that usually turns up something useful: "What are the common ways tests get this flow wrong?" Answers tend to include clock skew on token validation, reusing a token across environments, and refresh tokens that can only be used once.

I also ask about isolation: should the suite authenticate once per session or per test, and what are the trade-offs? The assistant gives me a framework, and the real API's token lifetime decides. The resulting checklist sits beside me while I write the auth fixture. The fixture patterns themselves are in testing OAuth-protected APIs without hardcoding tokens.

Brainstorm edge cases, then rank them

With the happy path mapped, I use the chat for adversarial brainstorming: "What edge cases and boundary conditions should I test on this endpoint that a developer might not have documented?" The list is usually broad: empty string versus null versus missing, very large numeric IDs, unusual characters in strings, duplicate requests with the same idempotency key, page zero and pages past the end. Some I'd have reached eventually. Getting them on day one is the value.

Then I ask it to group them by risk: which are most likely to catch a real regression, and which are lower priority. That rough ranking decides what goes into the smoke suite and what waits for the full run. I make the final call, because the model knows nothing about which parts of this system have broken before.

Turn every claim into a check

This is the step that turns a chat into testing. Each claim from the recon session that matters becomes a row in a small table of checks run against a sandbox. If a claim is wrong, the test says so, with the response that proves it:

import pytest

# Claims from the recon session, checked against the sandbox.
CLAIMS = [
    ("missing customer_id is rejected",
     {"items": [{"sku": "A1", "qty": 1}]}, 422),
    ("qty of zero is rejected",
     {"customer_id": "c1", "items": [{"sku": "A1", "qty": 0}]}, 422),
    ("empty items list is rejected",
     {"customer_id": "c1", "items": []}, 422),
]


@pytest.mark.recon
@pytest.mark.parametrize("claim, payload, expected", CLAIMS, ids=[c[0] for c in CLAIMS])
def test_recon_claim(sandbox_api, claim, payload, expected):
    resp = sandbox_api.post("/orders", json=payload)
    assert resp.status_code == expected, (
        f"claim not confirmed: {claim} (got {resp.status_code}: {resp.text[:300]})"
    )

sandbox_api is a client fixture pointed at a non-production environment with test credentials. When a check fails, either the assistant was wrong, the docs are wrong, or the API has a bug. All three are worth knowing before you build a suite on top. The confirmed claims become the seed of your real tests, with proper assertions on the error body as well as the status. For phrasing prompts so their output maps cleanly to assertions, see writing AI prompts that produce testable API assertions.

Letting an agent explore the sandbox

A chat only knows what you paste into it. A coding agent with a terminal (Claude Code, Copilot's agent mode and similar tools) can send requests itself, which makes it useful for exploratory recon: trying the edge cases from the brainstorm and reporting what actually happens. That power needs limits. These are the rules I give it:

## API recon rules
- Only call the sandbox base URL in .env.sandbox. Never any other host.
- Use the sandbox test key only. Never ask for or use production credentials.
- GET freely. POST/PUT/DELETE only on resources you created in this session.
- Log every request and response (redacting the Authorization header) to recon/log.jsonl.
- Report findings as: what you sent, what came back, why it looks wrong.
- Do not write or change tests. Findings go to recon/findings.md for review.

The log is non-negotiable. Every finding must point to a real exchange, so I can check it and the agent can't describe a response it never received. I read the findings, discard the noise, and promote the real ones into the claims table or straight into tests. Exploration stays separate from test-writing, which keeps a human between "the agent saw something" and "the suite now asserts it".

Keep data in mind too. If the agent creates records, they should be synthetic and clearly tagged so they can be cleaned up, and nothing copied from production should end up in a prompt or a log. Generating test data with AI without leaking real data covers how I handle that.

What I walk away with

A good recon session leaves me with a contract map tied to quotes from the spec, an auth checklist, a ranked list of edge cases, and a small set of executable checks that confirm or reject what the assistant told me. That's a much better starting point than a blank test file and an out-of-date document. If you want to take that starting point all the way to a maintained suite, my API testing courses build one with GitHub Copilot in VS Code.