Guides
Run API tests in CI
Write tests in the API client, commit the workspace to Git, and run them in GitHub Actions with cloakctl collection run and a JUnit report.
Cloak Proxy’s API client is a collection of plain JSON files, so your requests and their tests live in Git and run in CI with no app, like Newman or the Postman CLI. This guide writes tests on a request, commits the workspace, and runs the collection in GitHub Actions, exporting JUnit XML for the test report.
What you need
Section titled “What you need”| The API client with a collection and an environment | See Collections and requests |
cloakctl available in CI |
It ships inside the app bundle at Contents/Resources/cloakctl; CI usually runs it from a checked-out copy or a linked path |
| A Git repository for the workspace | The runner reads the folder of JSON files directly |
Write tests on a request
Section titled “Write tests on a request”-
In the API Client (
<kbd>⇧</kbd> <kbd>⌘</kbd> <kbd>O</kbd>), open a request and go to its Scripts tab, then Post-response. Write assertions withpm.testandpm.expect.Post-response tests on a request, with results below.
- Scripts tab
- Post-response phase
- pm.test / pm.expect assertions
- Test Results after Send
-
Use the Snippets menu for common checks (status is 2xx, response time, JSON value, schema). Press Send to run them; results appear under Test Results.
pm.test("Status code is 2xx", () => pm.response.to.be.success);pm.test("Responds within 500 ms", () => pm.expect(pm.response.responseTime).to.be.below(500));const json = pm.response.json();pm.test("Has a name", () => pm.expect(json).to.have.property("name"));Check the run locally
Section titled “Check the run locally”Open Collections, select the collection, and click Run to open the runner. Set iterations, pick a dataset or data file for data-driven runs, and run it.
The collection runner. The same run happens headlessly in CI.
- Iterations and options
- A dataset or CSV/JSON data file
- Passed / failed summary
- Export Results: JSON, JUnit XML, HTML
Commit the workspace to Git
Section titled “Commit the workspace to Git”The workspace is a folder of small, pretty-printed JSON files — one per request — so it diffs and merges cleanly. Secret values stay in a git-ignored .cloak/ folder.
- cloak-workspace.json
Directorycollections/
DirectoryPetstore/
- collection.json
- List pets.request.json
- Create pet.request.json
Directoryenvironments/
- Staging.environment.json
Directoryspecs/
- …
Directory.cloak/ (git-ignored: secret values, local state)
- …
- .gitignore
-
Open the Git view in the API client to see the workspace folder. Use Change Folder… to point the workspace at your repo, or Initialize Repository to start one.
The Git view: the workspace folder, ready to commit.
- Git section
- Workspace folder path
- Change Folder to point at your repo
- Initialize Repository
-
Commit from the Git view (enter a message and Commit All), or from your terminal. Confirm
.cloak/is ignored before you push.
Run it in GitHub Actions
Section titled “Run it in GitHub Actions”cloakctl collection run runs the collection with its scripts and tests and returns a non-zero exit code when any test or request fails. Export JUnit XML for the test report.
cloakctl collection run Petstore -e Staging -r cli,junit --reporter-junit-export results.xmlname: API testson: [push, pull_request]jobs: test: runs-on: macos-14 steps: - uses: actions/checkout@v4 - name: Run collection run: | cloakctl collection run Petstore \ -e Staging \ -r cli,junit \ --reporter-junit-export results.xml - name: Publish test report if: always() uses: actions/upload-artifact@v4 with: name: api-test-results path: results.xmlThe flags you’ll use
Section titled “The flags you’ll use”| Flag | What it does |
|---|---|
-e ENV |
Run with an environment (name or a .json file) |
-d DATA |
A dataset name or CSV/JSON data file: one iteration per row |
-n N |
Iteration count |
--folder NAME |
Run only one folder |
--bail |
Stop after the first failure |
--timeout-request MS |
Per-request timeout |
--insecure |
Skip TLS verification (same as -k) |
-r cli,json,junit,html |
Which reporters to produce |
--reporter-junit-export FILE |
Where to write the JUnit XML |
--reporter-json-export FILE |
Where to write the JSON report |
--reporter-html-export FILE |
Where to write the HTML report |
--env-var KEY=VALUE |
Override or add an environment variable |
--workspace DIR |
Use a specific workspace folder |
Exit code is 1 when any test or request fails, which fails the CI step.