test-management-sync
Overview
Teams that manage test cases in a test management tool need
automation result sync - without it, automated runs don't update
the tool and the test-management view drifts from reality. The sync
job has the same five-step shape across every vendor; only the auth
model, the endpoints, and the case-ID scheme differ.
This skill wires that sync: the vendor-independent workflow below,
TestRail as the worked example, and per-vendor API detail in
references/.
Vendor routing
| Vendor |
Shape |
Auth |
Results API |
Reference |
| TestRail (Gurock / Idera) |
Standalone TCM (not a Jira app) |
Basic (email + API key) |
add_run + batched add_results_for_cases |
references/testrail.md |
| Xray |
Jira app (Test / Test Execution issue types) |
Cloud: client_id+client_secret → 24h JWT; Server/DC: PAT |
/api/v2/import/execution/{junit,cucumber,nunit,testng,robot} |
references/xray.md |
| Zephyr Scale (SmartBear, formerly TM4J) |
Jira app (Test Cycles) |
Long-lived Bearer token |
POST /testexecutions (or bulk /automations/executions/junit) |
references/zephyr.md |
Routing rules:
- Test management is standalone TestRail → references/testrail.md.
- Test management is a Jira app → Xray (references/xray.md) or
Zephyr Scale (references/zephyr.md) - check which app the Jira
instance has installed; Zephyr further disambiguates into Scale / Squad / Enterprise
(the zephyr reference's variant table).
- The team wants cross-run flakiness analytics, not case sync →
currents-integration (different job entirely).
When to use
- The team runs both manual and automated tests and the automated
results need to land in the test management tool.
- A CI pipeline must auto-create a run / execution / cycle per build
and populate results so release management has the full picture.
- The team manages test cases in the tool and wants per-case mapping
back to the automated test (via case-ID labels in test names or
annotations).
The push-results workflow (vendor-independent)
Every vendor sync follows the same five steps:
- Authenticate from CI secrets - never URL params, never logged
(TestRail: Basic email+key; Xray Cloud: JWT exchange per run;
Zephyr Scale: Bearer token).
- Map tests to case IDs - embed the vendor's case ID / issue key
in the test name (
test('adds to cart [C1234]')) or use an
annotation (@XrayTest(key=...), @TestRailCase(id=...),
@TestCaseKey(...)). Name-embedding is lowest-friction; either
way the sync script must recover the ID from the result.
- Open a container per build - a TestRail Test Run, an Xray Test
Execution, or a Zephyr Test Cycle - scoped to exactly the cases
the automated suite covers, named
<branch> · <sha-short>.
- Batch results back - one batched POST (or bounded-concurrency
loop) rather than one call per test; every vendor has a rate limit
that per-test posting trips on real suites.
- Close / finalize on
main only - closed containers are
read-only; PR runs stay open so flake-fix reruns can update them.
Run the sync as an if: always() CI step after the test step so
failed runs still update the tool. The input is the runner's JUnit
XML - parse it with junit-xml-analysis.
Worked example - TestRail
A Jest suite syncing one build to TestRail project 42, suite 7.
- Tests carry the case ID in the name (Step 2, name-embedding):
test('can add to cart [C1234]', ...).
- Export credentials and run the suite to JUnit XML:
export TESTRAIL_HOST=https://acme.testrail.io
export TESTRAIL_USER=ci@acme.com
export TESTRAIL_API_KEY=... # My Settings > API Keys
npm test -- --reporters=jest-junit
- The sync script opens a run scoped to the covered cases
(
include_all: False + explicit case_ids - without this a
5,000-case project produces a 5,000-row run of empty cells), then
batches the results in one POST:
run_id = open_run(42, 7, "main · a1b2c3d", [1234]) # add_run → Run ID
add_results(run_id, [ # add_results_for_cases (batch)
{'case_id': 1234, 'status_id': 1, 'comment': 'green on CI', 'elapsed': '12s'},
])
status_id: 1 is Passed per the stock convention (1 Passed /
2 Blocked / 3 Untested / 4 Retest / 5 Failed) - but read
get_statuses at script init and verify every ID in your map exists,
because TestRail accepts unknown IDs and writes to the wrong status
silently. Full script, per-result fields, and CI wiring:
references/testrail.md.
- Open the run in TestRail to see
C1234 marked Passed with the
12s elapsed time. Close the run only when this is the main
build (Step 5).
For the same build against Xray the container is a Test Execution
fed by POST /api/v2/import/execution/junit?projectKey=...
(references/xray.md); against Zephyr Scale it
is a Test Cycle fed by POST /testexecutions
(references/zephyr.md).
Anti-patterns (all vendors)
| Anti-pattern |
Why it fails |
Fix |
| Per-test result POSTs |
N API calls trip every vendor's rate limit (TestRail 180 req/min, Zephyr 60 req/min). |
Batch (TestRail add_results_for_cases, Xray format import) or bound concurrency (Zephyr). |
| Hard-coded status IDs / names |
Custom statuses break the mapping silently. |
Fetch the status list at script init; build the map dynamically. |
| Auto-creating cases / issues from CI |
Every renamed test creates a new case; the project fills with orphans. |
Pre-create cases; sync references existing IDs only. |
| Posting credentials as URL params or logging tokens |
Secrets leak in proxy logs / CI logs. |
Auth headers only; mask tokens (::add-mask::). |
| Closing every run, including PR runs |
Closed runs can't accept the rerun after a flake fix. |
Close / finalize only main runs. |
| One container reused across many builds |
The run accumulates noise; release sign-off is unreadable. |
One run / execution / cycle per build. |
Sync step not if: always() |
Failed test runs - the ones release management most needs - never sync. |
if: always() after the test step. |
Limitations
- Cases must already exist in the tool. The sync maps results to
existing case IDs; it doesn't author cases (that's
qa-test-management's
tcm-case-management).
- The mapping lives in test names / annotations. Renames that
drop the ID silently unmap the test - surface unmapped tests as
warnings, never drop them (per-vendor references show how).
- Vendor APIs differ in batch semantics. TestRail batches
natively, Xray imports whole runner files, Zephyr Scale is
per-execution with bounded concurrency - don't port one vendor's
script shape blindly to another.
References
- references/testrail.md - TestRail auth, case-ID mapping,
add_run / add_results_for_cases / close_run, per-result fields, CI wiring, untested-case handling.
- references/xray.md - Xray Cloud JWT auth, per-format import endpoints,
@XrayTest / @Requirement mapping, testExecKey lifecycle, Playwright reporter.
- references/zephyr.md - Zephyr Scale variant disambiguation, Bearer auth, Test Cycles,
/testexecutions, bounded-concurrency batching, bulk JUnit import.
junit-xml-analysis - upstream parser for the input every sync script consumes.
currents-integration - different role: test analytics over time, not test management.
1---2name: test-management-sync3description: "Use when CI test results must flow into TestRail, Xray for Jira or Zephyr Scale without manual copying. Maps tests to case IDs, opens a run per build, pushes results in batches and closes runs on main only; vendor details are in its references."4metadata:5 source: https://skillmd.com/skills/testland/test-management-sync6---78# test-management-sync910## Overview1112Teams that manage test cases in a test management tool need13**automation result sync** - without it, automated runs don't update14the tool and the test-management view drifts from reality. The sync15job has the same five-step shape across every vendor; only the auth16model, the endpoints, and the case-ID scheme differ.1718This skill wires that sync: the vendor-independent workflow below,19TestRail as the worked example, and per-vendor API detail in20`references/`.2122## Vendor routing2324| Vendor | Shape | Auth | Results API | Reference |25|---|---|---|---|---|26| **TestRail** (Gurock / Idera) | Standalone TCM (not a Jira app) | Basic (email + API key) | `add_run` + batched `add_results_for_cases` | [references/testrail.md](references/testrail.md) |27| **Xray** | Jira app (Test / Test Execution issue types) | Cloud: `client_id`+`client_secret` → 24h JWT; Server/DC: PAT | `/api/v2/import/execution/{junit,cucumber,nunit,testng,robot}` | [references/xray.md](references/xray.md) |28| **Zephyr Scale** (SmartBear, formerly TM4J) | Jira app (Test Cycles) | Long-lived Bearer token | `POST /testexecutions` (or bulk `/automations/executions/junit`) | [references/zephyr.md](references/zephyr.md) |2930Routing rules:3132- Test management is **standalone TestRail** → [references/testrail.md](references/testrail.md).33- Test management is a **Jira app** → Xray ([references/xray.md](references/xray.md)) or34 Zephyr Scale ([references/zephyr.md](references/zephyr.md)) - check which app the Jira35 instance has installed; Zephyr further disambiguates into Scale / Squad / Enterprise36 (the zephyr reference's variant table).37- The team wants **cross-run flakiness analytics**, not case sync →38 `currents-integration` (different job entirely).3940## When to use4142- The team runs both manual and automated tests and the automated43 results need to land in the test management tool.44- A CI pipeline must auto-create a run / execution / cycle per build45 and populate results so release management has the full picture.46- The team manages test cases in the tool and wants per-case mapping47 back to the automated test (via case-ID labels in test names or48 annotations).4950## The push-results workflow (vendor-independent)5152Every vendor sync follows the same five steps:53541. **Authenticate** from CI secrets - never URL params, never logged55 (TestRail: Basic email+key; Xray Cloud: JWT exchange per run;56 Zephyr Scale: Bearer token).572. **Map tests to case IDs** - embed the vendor's case ID / issue key58 in the test name (`test('adds to cart [C1234]')`) or use an59 annotation (`@XrayTest(key=...)`, `@TestRailCase(id=...)`,60 `@TestCaseKey(...)`). Name-embedding is lowest-friction; either61 way the sync script must recover the ID from the result.623. **Open a container per build** - a TestRail Test Run, an Xray Test63 Execution, or a Zephyr Test Cycle - scoped to exactly the cases64 the automated suite covers, named `<branch> · <sha-short>`.654. **Batch results back** - one batched POST (or bounded-concurrency66 loop) rather than one call per test; every vendor has a rate limit67 that per-test posting trips on real suites.685. **Close / finalize on `main` only** - closed containers are69 read-only; PR runs stay open so flake-fix reruns can update them.7071Run the sync as an `if: always()` CI step after the test step so72failed runs still update the tool. The input is the runner's JUnit73XML - parse it with `junit-xml-analysis`.7475## Worked example - TestRail7677A Jest suite syncing one build to TestRail project `42`, suite `7`.78791. Tests carry the case ID in the name (Step 2, name-embedding):80 `test('can add to cart [C1234]', ...)`.812. Export credentials and run the suite to JUnit XML:8283```bash84export TESTRAIL_HOST=https://acme.testrail.io85export TESTRAIL_USER=ci@acme.com86export TESTRAIL_API_KEY=... # My Settings > API Keys87npm test -- --reporters=jest-junit88```89903. The sync script opens a run scoped to the covered cases91 (`include_all: False` + explicit `case_ids` - without this a92 5,000-case project produces a 5,000-row run of empty cells), then93 batches the results in **one** POST:9495```python96run_id = open_run(42, 7, "main · a1b2c3d", [1234]) # add_run → Run ID97add_results(run_id, [ # add_results_for_cases (batch)98 {'case_id': 1234, 'status_id': 1, 'comment': 'green on CI', 'elapsed': '12s'},99])100```101102`status_id: 1` is Passed per the stock convention (1 Passed /1032 Blocked / 3 Untested / 4 Retest / 5 Failed) - but read104`get_statuses` at script init and verify every ID in your map exists,105because TestRail accepts unknown IDs and writes to the wrong status106silently. Full script, per-result fields, and CI wiring:107[references/testrail.md](references/testrail.md).1081094. Open the run in TestRail to see `C1234` marked Passed with the110 `12s` elapsed time. Close the run only when this is the `main`111 build (Step 5).112113For the same build against Xray the container is a Test Execution114fed by `POST /api/v2/import/execution/junit?projectKey=...`115([references/xray.md](references/xray.md)); against Zephyr Scale it116is a Test Cycle fed by `POST /testexecutions`117([references/zephyr.md](references/zephyr.md)).118119## Anti-patterns (all vendors)120121| Anti-pattern | Why it fails | Fix |122|---------------------------------------------------------------------------|-------------------------------------------------------------------------------|-----|123| Per-test result POSTs | N API calls trip every vendor's rate limit (TestRail 180 req/min, Zephyr 60 req/min). | Batch (TestRail `add_results_for_cases`, Xray format import) or bound concurrency (Zephyr). |124| Hard-coded status IDs / names | Custom statuses break the mapping silently. | Fetch the status list at script init; build the map dynamically. |125| Auto-creating cases / issues from CI | Every renamed test creates a new case; the project fills with orphans. | Pre-create cases; sync references existing IDs only. |126| Posting credentials as URL params or logging tokens | Secrets leak in proxy logs / CI logs. | Auth headers only; mask tokens (`::add-mask::`). |127| Closing every run, including PR runs | Closed runs can't accept the rerun after a flake fix. | Close / finalize only `main` runs. |128| One container reused across many builds | The run accumulates noise; release sign-off is unreadable. | One run / execution / cycle per build. |129| Sync step not `if: always()` | Failed test runs - the ones release management most needs - never sync. | `if: always()` after the test step. |130131## Limitations132133- **Cases must already exist in the tool.** The sync maps results to134 existing case IDs; it doesn't author cases (that's135 qa-test-management's `tcm-case-management`).136- **The mapping lives in test names / annotations.** Renames that137 drop the ID silently unmap the test - surface unmapped tests as138 warnings, never drop them (per-vendor references show how).139- **Vendor APIs differ in batch semantics.** TestRail batches140 natively, Xray imports whole runner files, Zephyr Scale is141 per-execution with bounded concurrency - don't port one vendor's142 script shape blindly to another.143144## References145146- [references/testrail.md](references/testrail.md) - TestRail auth, case-ID mapping, `add_run` / `add_results_for_cases` / `close_run`, per-result fields, CI wiring, untested-case handling.147- [references/xray.md](references/xray.md) - Xray Cloud JWT auth, per-format import endpoints, `@XrayTest` / `@Requirement` mapping, `testExecKey` lifecycle, Playwright reporter.148- [references/zephyr.md](references/zephyr.md) - Zephyr Scale variant disambiguation, Bearer auth, Test Cycles, `/testexecutions`, bounded-concurrency batching, bulk JUnit import.149- `junit-xml-analysis` - upstream parser for the input every sync script consumes.150- `currents-integration` - different role: test analytics over time, not test management.