Boxing in the LLM: REST Assured to Postman with Claude Code

Boxing in the LLM: REST Assured to Postman with Claude Code

User Avatar

Migrating a mature Java API test suite into Postman sounds like a job for an LLM until you try it. A single REST Assured project can carry hundreds of @Test methods across dozens of classes, a BaseTest that sets the base URI in a @BeforeSuite, parameterized data providers, a few WireMock stubs, and a TestNG suite XML that quietly decides which classes run. Hand all of it to a model in one prompt and you get creative fiction. Hand it one class at a time, inside boring deterministic scaffolding, and you get correctness.

That’s the architecture we landed on when we built Postman’s REST Assured converter, and it carries over to a workflow you can run on your own machine. In this post you’ll convert a REST Assured project to a Postman Collection with Claude Code and the Postman plugin. A shell for loop decides what to convert and how many pieces there are. A boxed-in worker converts one test class at a time. The plugin’s skills supply the collection file format, run the result, and gate it in CI. The most reliable agent in the system is the for loop.

Box in the model

Every decision downstream flows from one choice: what counts as a unit of work the model is allowed to reason about? We picked one Java test class. A method is too little context, because data providers and helper methods live at the class level. A whole project is too much, and the model starts inventing cross-class references. Once you commit to that boundary, the rest of the design follows:

Job Who does it Why
Find the test classes A regex JUnit 5 and TestNG markers are well defined, so there’s no reason to spend tokens looking for them
Resolve shared config such as the base URI One model call, once Every worker reuses the answer, so you don’t get N different names for the same variable
Fan out across classes A for loop with retries When a class fails, it fails alone
Translate one class A worker with read-only tools This is the part that needs judgment
Write files and assemble the collection Code No model call decides where a file goes
Check the result The Postman CLI Lint checks structure and a run checks behavior

In the production converter, the scheduling is p-map with a concurrency of 6, each unit gets three attempts, and the whole pipeline has a 30-minute timeout. A unit that fails all three attempts lands in a failed list and the run keeps going. There is no coordinator agent: no orchestrator LLM watching the run, no planner picking the next unit. The agent is a function that the loop calls, so the LLM lives at the leaves of the call tree, not the root.

What you need

  • Claude Code with the claude command on your path
  • The Postman CLI (the plugin’s cli-install skill can install it if it’s missing)
  • jq and a Unix shell
  • A REST Assured project with JUnit 5 or TestNG tests

Install the Postman plugin

One command installs the plugin into each supported agent it detects, including Claude Code:

npx @postman/postman-plugin

The plugin gives Claude skills for API engineering. Each skill holds instructions the agent reads for a task. This workflow touches four of them: collection-schema-v3 for the collection file format, api-testing for running assertions, api-mocking for stubs, and ci-integration for the pull request gate. Linting and running a collection locally don’t require you to sign in to Postman. You only need to sign in when you publish to a workspace.

Step 1: Discover test classes with grep

Before any model runs, a discovery pass walks the project with plain tools. The marker count it records becomes the coverage target for each class. Create scripts/discover.sh:

#!/usr/bin/env bash
# Step 1: find every test class and count its test markers. No model involved.
set -euo pipefail
MARKER='@([A-Za-z0-9_.]*\.)?(Test|ParameterizedTest|RepeatedTest|TestFactory|TestTemplate)([^A-Za-z0-9_]|$)'

grep -rlE "$MARKER" src/test/java | sort | while read -r file; do
  printf '%s\t%s\n' "$file" "$(grep -cE "$MARKER" "$file")"
done > units.tsv

cat units.tsv

On the demo project, which has a BaseTest plus UsersTest and PostsTest, the output looks like this:

src/test/java/com/example/PostsTest.java    3
src/test/java/com/example/UsersTest.java    2

BaseTest has no test markers, so it isn’t a unit. It’s context the workers will read. Over-inclusion is fine at this stage. A class with no HTTP calls comes back with an empty list, while a class that never got enumerated is a bug you may not notice for months.

Step 2: Resolve shared configuration once

Most REST Assured projects build a shared RequestSpecBuilder in a base class. If every worker rediscovered it independently, you’d get a different guess at the variable name from each one. So a single resolver call runs first, with a prompt that is aggressively narrow. Save it as prompts/resolver.md:

Resolve the CROSS-CUTTING configuration shared across all tests in this Java API-test project.
Do this ONCE: every test class will reuse your output. You are NOT converting tests here.

Look for a base class or @BeforeSuite/@BeforeClass block that sets the base URI, shared
headers, content type, or authentication. Use the read, glob, and grep tools.

Return ONLY a single JSON object, with no prose and no code fence, in exactly this shape:
{"variables":[{"key":"baseUrl","value":"https://..."}],"brief":"two or three sentences about shared setup the converters need to know"}

Then call it from scripts/resolve.sh. The --allowedTools flag is the box: this call can read files and nothing else. Redirecting stdin from /dev/null keeps claude -p from waiting on a pipe.

#!/usr/bin/env bash
# Step 2: one model call that resolves shared configuration.
set -euo pipefail

claude -p "$(cat prompts/resolver.md)" \
  --allowedTools "Read,Glob,Grep" \
  --output-format json < /dev/null \
  | jq -r '.result' \
  | sed -e '/^```/d' > resolved.json

jq -e '.variables and .brief' resolved.json > /dev/null
cat resolved.json

The last jq -e line is a deterministic check on a probabilistic step. If the model returns anything other than the shape you asked for, the script stops. On the demo project, the resolver returns this:

{
  "variables": [
    { "key": "baseUrl", "value": "https://jsonplaceholder.typicode.com" }
  ],
  "brief": "BaseTest.setupSpec() (@BeforeSuite) sets a global RestAssured request spec with base URI https://jsonplaceholder.typicode.com and Content-Type application/json. There is no authentication and there are no other shared headers or base path."
}

The worker never has to guess what to name baseUrl, because it was told.

Step 3: Convert one class at a time with a for loop

The worker prompt is explicit about its boundary. It converts exactly one class, it can’t write files, and it has to return JSON. Save it as prompts/worker.md:

You convert exactly ONE Java REST Assured test class into Postman v3 request files.
You have read-only tools (read, glob, grep) scoped to this project. You cannot write
files or run commands. Read the class named at the end of this prompt, and follow
base classes, helpers, and data providers it depends on.

Use the collection-schema-v3 skill for the exact shape of *.request.yaml files.

Rules:
- Write one request per @Test method. If a data provider changes the request, write one request per row.
- Use {{baseUrl}} for the base URI. Never hardcode the host. Reuse the variable names from the shared setup below.
- Put assertions in an afterResponse script, using pm.test and pm.expect.
- Translate REST Assured and Hamcrest like this:

  .statusCode(n)                  -> pm.response.to.have.status(n)
  .body("json.path", matcher)     -> assert on pm.response.json() at that path
  .time(lessThan(ms))             -> pm.expect(pm.response.responseTime).to.be.below(ms)
  .header(k, v)                   -> pm.expect(pm.response.headers.get(k)).to.eql(v)
  equalTo(x) / is(x)              -> .to.eql(x)
  hasItem(x) / containsString(s)  -> .to.include(x)
  greaterThan(n) / lessThan(n)    -> .to.be.above(n) / .to.be.below(n)
  notNullValue() / nullValue()    -> .to.exist / .to.not.exist
  hasSize(n)                      -> .to.have.lengthOf(n)

Return ONLY a JSON object, with no prose and no code fence, in exactly this shape:
{"requests":[{"file":"get-user-by-id.request.yaml","yaml":"<the full file contents>"}]}

This is where the model earns its keep. It maps the REST Assured fluent DSL and Hamcrest matchers onto pm.expect chains, which is a translation problem a model handles well. The prompt names the collection-schema-v3 skill so the worker gets the exact file shape instead of recalling it. In a streamed run of the demo, the worker reads the class, calls the skill, and reads the skill’s files before it answers.

Now the loop itself, scripts/convert.sh. It reads units.tsv, gives each class three attempts, checks that the request count meets the marker count, and only then writes files:

#!/usr/bin/env bash
# Step 3: the for loop. One worker per test class, three attempts each.
set -uo pipefail
OUT=postman/collections/rest-assured
mkdir -p "$OUT/.resources"; : > failed-units.txt

# The collection definition comes from the resolver output. No model involved.
jq -r '"$kind: collection\nname: REST Assured tests\nvariables:" +
  ([.variables[] | "\n  - key: \(.key)\n    value: \(.value | @json)"] | join(""))' \
  resolved.json > "$OUT/.resources/definition.yaml"

while IFS=$'\t' read -r unit expected; do
  name=$(basename "$unit" .java)
  for attempt in 1 2 3; do
    prompt="$(cat prompts/worker.md)

Shared setup: $(cat resolved.json)
Unit to convert: $unit"

    claude -p "$prompt" \
      --allowedTools "Read,Glob,Grep,Skill" \
      --output-format json < /dev/null > "run-$name.json" 2> /dev/null || continue
    jq -r '.result' "run-$name.json" | sed -e '/^```/d' > "items-$name.json"

    returned=$(jq -e '.requests | length' "items-$name.json" 2> /dev/null) || continue
    if [ "$returned" -lt "$expected" ]; then
      echo "$name: attempt $attempt returned $returned of $expected, retrying"; continue
    fi

    mkdir -p "$OUT/$name"
    jq -c '.requests[]' "items-$name.json" | while read -r req; do
      file=$(jq -r '.file' <<< "$req" | tr -cd 'A-Za-z0-9._-')
      jq -r '.yaml' <<< "$req" > "$OUT/$name/$file"
    done
    echo "$name: $returned/$expected requests ($(jq -r '.num_turns' "run-$name.json") turns, \$$(jq -r '.total_cost_usd' "run-$name.json"))"
    continue 2
  done
  echo "$name" >> failed-units.txt
  echo "$name: failed after 3 attempts"
done < units.tsv

Run it:

chmod +x scripts/*.sh
./scripts/discover.sh && ./scripts/resolve.sh && ./scripts/convert.sh

On the demo project, each class converts on the first attempt:

PostsTest: 3/3 requests (5 turns, $0.308115)
UsersTest: 2/2 requests (5 turns, $0.309468)

Your turn counts and costs depend on your model and your project. The shape of the result matters more: the model never touched the file system. It returned JSON, and the loop validated it, counted it, and placed each file. A prompt-injected comment in a test file can’t make the worker write anything or run anything, because the worker has no tool that does either.

What the worker wrote

Here’s UsersTest.getUserById next to the request file the worker returned for it:

@Test
public void getUserById() {
    given()
    .when()
        .get("/users/1")
    .then()
        .statusCode(200)
        .body("id", equalTo(1))
        .body("name", equalTo("Leanne Graham"))
        .body("username", equalTo("Bret"))
        .body("email", equalTo("[email protected]"));
}
$kind: http-request
name: getUserById
method: GET
url: '{{baseUrl}}/users/1'
order: 1000
headers:
  - key: Content-Type
    value: application/json
scripts:
  - type: afterResponse
    language: text/javascript
    code: |-
      pm.test('status code is 200', () => {
        pm.response.to.have.status(200);
      });

      pm.test('user fields match', () => {
        const body = pm.response.json();
        pm.expect(body.id).to.eql(1);
        pm.expect(body.name).to.eql('Leanne Graham');
        pm.expect(body.username).to.eql('Bret');
        pm.expect(body.email).to.eql('[email protected]');
      });

The base URI is now the {{baseUrl}} collection variable, the Hamcrest matchers are pm.expect chains, and the test names are readable. Query parameters came through too. PostsTest.getPostsByUser has a userId parameter, and the worker recorded it in both the URL and the queryParams list, which is what the v3 format requires.

Step 4: Lint and run the collection

The converter’s job ends when files exist. The Postman CLI decides whether they’re any good. Lint checks structure:

postman collection lint postman/collections/rest-assured
No issues found.
Scanned: 5 | Errors: 0 | Warnings: 0 | 5ms

Then run the collection, which is the api-testing skill’s core move: reuse the saved requests and assertions as regression checks.

postman collection run postman/collections/rest-assured
Folder UsersTest
Sub-folder getUserById

  GET https://jsonplaceholder.typicode.com/users/1 [200 OK, 1.25 KB, 55 ms]
  Pass  status code is 200
  Pass  user fields match

...

|              iterations |                   1 |                   0 |
|                requests |                   5 |                   0 |
|            test-scripts |                   5 |                   0 |
|              assertions |                  12 |                   0 |

Five requests ran and all 12 assertions passed. Lint and a green run are two different guarantees. Lint says Postman can read the files. A run says the converted checks hold against the API. Neither says the converted checks match the original intent, so compare the counts. The demo’s Java tests contain 15 REST Assured checks, and they became 12 pm.test blocks, because the worker grouped the four field checks in getUserById into one test. That’s a reasonable choice, and it’s also the kind of thing to skim before you trust a migration.

Handle WireMock stubs with api-mocking

A project with WireMock stubs has a second kind of unit, and the demo scripts above don’t cover it. In the production converter, a class with no test markers but real stubFor blocks routes to a mock-specific prompt. You can add the same branch to this loop with a second marker pattern in discover.sh and a second worker prompt. Each stub becomes a request with a saved response example in the *.example.yaml format the collection-schema-v3 skill documents. From there the api-mocking skill takes over. postman mock generate builds a mock from a collection’s documented responses, and postman mock run serves it locally without a sign-in. A suite that needed a local WireMock process can point at that mock instead.

One caveat from the skill’s own guidance: a generated mock replays documented responses. A POST and a later GET share no state, so put the error cases your callers handle, such as the unknown-ID 404, into the examples. Read the mock command reference before you rely on a mock for behavior it can’t model.

Gate the collection in CI

Once the converted tests pass locally, the ci-integration skill’s job is to make a pull request carry them. Pick one gate per guarantee so a failed build tells you whether structure or behavior broke. This workflow lints first, then runs:

name: API checks

on:
  pull_request:
    paths:
      - 'postman/**'

jobs:
  collection-checks:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install the Postman CLI
        run: curl -o- "https://dl-cli.pstmn.io/install/linux64.sh" | sh

      - name: Lint the collection
        run: postman collection lint postman/collections/rest-assured -f error

      - name: Run the collection
        run: postman collection run postman/collections/rest-assured -r junit,html

The demo collection calls a public API, so it runs as is. For a real suite, point the job at a mock or a staging environment you’re willing to write to, because a collection run sends real requests. A local-only gate like this one needs no API key. Add postman login with a secret from your CI store when you want run results published to a workspace. See Run the Postman CLI in GitHub Actions for the details.

Things to watch for

  • Coverage is a count, not a guarantee. The marker count catches “the model got bored and stopped.” It can’t catch a request that exists but asserts the wrong thing.
  • Check failed-units.txt after every run. A failed class is named there. The collection is smaller than the project it came from but still valid, so the failure is hard to notice if you only look at the green run.
  • Treat the model’s output as untrusted input. Validate the JSON shape with jq, sanitize file names, and write files from the loop, never from the worker.
  • Keep the shell away from the worker. The read-only tool list is what makes the loop safe to point at a large codebase.
  • Don’t drop classes because a TestNG suite file omits them. Suite files go stale in real projects, so use them to report orphan classes only.

The generalizable idea

The REST Assured specifics don’t matter as much as the questions behind them. What is the smallest unit of work the model can reason about correctly on its own? Which parts of the problem are deterministic enough that code can own them outright? Where does the model earn its keep, and where are you paying token cost for a regex?

The answers reshape the architecture. Discovery becomes a regex pass. Shared configuration becomes a one-shot call. Fan-out becomes a for loop. Assembly becomes code that writes files. What’s left in the middle is a small, boxed-in agent doing a translation it’s good at.

The most useful thing we did was stop trying to make the agent smarter and start making the code around it dumber. The for loop doesn’t have opinions about REST Assured, doesn’t misremember which classes it already converted, and doesn’t run out of context. It keeps calling the worker until the units are gone.

Try it yourself

Copy the three scripts and two prompts from this post into the root of your Maven or Gradle project, then work through it in this order:

  1. Run npx @postman/postman-plugin to install the plugin.
  2. Run ./scripts/discover.sh and check that units.tsv lists the classes you expect.
  3. Run ./scripts/resolve.sh and read resolved.json. If the variable name or base URI is wrong, fix the prompt before you convert anything.
  4. Trim units.tsv to one or two classes and run ./scripts/convert.sh.
  5. Run postman collection lint and postman collection run on the output, then compare the REST Assured check count with the pm.test count.
  6. Restore the full units.tsv, run the loop again, and open failed-units.txt.

Then change one thing and watch what happens. Add a data provider to a test and see whether the worker writes one request per row. Remove Skill from --allowedTools and compare the generated files. Add a class with no HTTP calls and confirm it returns an empty list.

Resources

Comment

Your email address will not be published. Required fields are marked *


This site uses Akismet to reduce spam. Learn how your comment data is processed.