Migrating from Postman / Newman to the Mockarty Tester
Use this guide when you want to move Postman checks into code that lives with
your application tests. It shows how to import a collection into a Mockarty
Tester flow or rewrite its checks step by step. If you want to keep your
existing collection file and run it in CI, use the Postman/Newman migration
guide instead.
Two import paths. If you already have a
.postman_collection.json,
the CLI can convert it to the canonical IR and emit Go/Python/Java
source automatically. If you’re starting fresh, write the Tester
chain directly — the API was designed to read like Postman’s
“Pre-request Script + Tests + Send” trio.
At a glance
| Postman | Mockarty Tester |
|---|---|
pm.sendRequest(...) |
t.HTTP().GET(...) / .POST(...) |
pm.test("name", fn) |
One chain step — the assertion verb names it |
pm.expect(x).to.equal(y) |
.ExpectJSONPath("$.x", y) |
pm.response.code |
.ExpectStatus(200) |
pm.response.json() |
.ExpectJSONPath("$.field", value) |
pm.environment.set("k", v) |
.Extract("$.k", "v") / t.SetVar("k", v) |
pm.environment.get("k") |
{{k}} template inside any chain string |
| Collection folders | t.Wrap("group name", func() { ... }) |
| Pre-request script | Plain code before the chain |
| Environment file | Map passed to WithVar(...) or t.SetVar(...) calls |
pm.expect(arr.length).to.equal(2) |
.ExpectJSONArrayLen("$.arr", 2) |
| Bearer auth | .Header("Authorization", "Bearer {{token}}") |
Auto-import a Postman collection
mockarty-cli flow import users.postman_collection.json -o users.ir.json
mockarty-cli flow gen users.ir.json -o users_test.go
mockarty-cli flow run users_test.go
The importer maps Postman folders → Wrap blocks, requests → HTTP
steps, bearer/apikey/basic auth → headers, and preserves Postman test
scripts as postman_script IR steps so the source survives the
round-trip. Then flow gen renders Go source driving the Tester.
Target other languages
flow gen emits Go by default. Pass --to py | java | kotlin to
render the same flow in a different SDK:
mockarty-cli flow gen users.ir.json --to py -o users_test.py
mockarty-cli flow gen users.ir.json --to java -o UsersTest.java
mockarty-cli flow gen users.ir.json --to kotlin -o UsersTest.kt
All four outputs drive the same Mockarty Tester surface, so a flow
written once can ship to any language’s test suite without rewriting
assertions or extracts. --package controls the Go / Java / Kotlin
package (ignored for Python); --base-url inlines a base URL instead
of reading MOCKARTY_BASE_URL from the environment at runtime.
Run an IR document on the server
When you don’t want to spin up a local toolchain, flow exec posts
the IR straight at your Mockarty admin and prints the aggregated
result:
mockarty-cli flow exec users.ir.json --server https://mocks.example
# status: passed
# duration: 124ms
The CLI exits non-zero when the run failed, so it drops into set -e
shells naturally. Pair with flow import to replace Newman in CI:
mockarty-cli flow import users.postman_collection.json -o users.ir.json && \
mockarty-cli flow exec users.ir.json
Hand-written migration — side by side
Postman collection (JSON, abbreviated)
{
"info": {"name": "Login flow"},
"item": [{
"name": "login",
"request": {
"method": "POST",
"url": "{{base_url}}/login",
"body": {"mode":"raw","raw":"{\"user\":\"alice\"}"}
},
"event":[{"listen":"test","script":{"exec":[
"pm.test('status', function () { pm.expect(pm.response.code).to.equal(200); });",
"var data = pm.response.json();",
"pm.environment.set('token', data.token);"
]}}]
}, {
"name": "me",
"request": {
"method": "GET",
"url": "{{base_url}}/me",
"header": [{"key":"Authorization","value":"Bearer {{token}}"}]
},
"event":[{"listen":"test","script":{"exec":[
"pm.test('user', function () { pm.expect(pm.response.json().user).to.equal('alice'); });"
]}}]
}]
}
Mockarty Tester — Go
package main
import (
"log"
"os"
"github.com/mockarty/mockarty-go/tester"
)
func main() {
t := tester.New(tester.WithBaseURL(os.Getenv("BASE_URL")))
t.HTTP().POST("/login").
JSON(map[string]any{"user": "alice"}).
ExpectStatus(200).
Extract("$.token", "token")
t.HTTP().GET("/me").
Header("Authorization", "Bearer {{token}}").
ExpectJSONPath("$.user", "alice")
t.Finish()
if !t.OK() {
for _, e := range t.Errors() { log.Println(e) }
os.Exit(1)
}
}
Mockarty Tester — Python
from mockarty.tester import Tester
with Tester(base_url="http://localhost:8080") as t:
(t.http().post("/login")
.json({"user": "alice"})
.expect_status(200)
.extract("$.token", "token"))
(t.http().get("/me")
.header("Authorization", "Bearer {{token}}")
.expect_json_path("$.user", "alice"))
assert t.ok(), t.errors()
Mockarty Tester — Java
Tester t = new Tester.Builder().baseUrl(System.getenv("BASE_URL")).build();
t.http().post("/login")
.json(Map.of("user", "alice"))
.expectStatus(200)
.extract("$.token", "token");
t.http().get("/me")
.header("Authorization", "Bearer {{token}}")
.expectJsonPath("$.user", "alice");
t.finish();
if (!t.ok()) throw new AssertionError(t.errors());
What the Tester gives you that Newman doesn’t
- Multi-protocol — the same chain syntax works for HTTP, gRPC,
GraphQL, WebSocket, SSE, Kafka, RabbitMQ, SOAP, and DB. Postman is
HTTP-centric. - Real language runtime — Go / Python / Java idioms, not a
sandboxed JS subset. Use your IDE’s autocomplete, your team’s
helper libraries, your CI’s secret store. - Allure output by default — wrap a test in
allure.WithTest
and every chain call lands as an Allure step.mockarty-cli allure uploadships them into TCM. - Variable interpolation across protocols — extract a token from
an HTTP login and use it in a Kafka header on the next step,
without writing the plumbing.
Reporting back to Mockarty TCM
Once the chain runs, ship the result as an external run:
client.ExternalRuns().Report(ctx, "qa",
t.ToExternalRun(tester.ExternalRunOptions{
CaseName: "Login flow",
AutoCreate: true,
}),
)
Each chain step lands as an external-run step with the protocol /
method / URL in its metadata bag — the TCM run page renders it the
same way it renders native test-plan steps.
See also: Postman / Newman server migration
(for users replacing WireMock-style Postman mock servers rather
than the test runner).