Skip to main content

Send TestNG Results to Vansah from GitHub Actions

Configure TestNG mappings and a GitHub workflow that uploads XML results to Vansah, checks the import, and preserves failed test outcomes.

Run TestNG tests in GitHub Actions and upload their XML results to existing Vansah Test Cases. This workflow uses your workspace’s API Connect URL and checks that rows were imported successfully.

Before you begin

  • Your Maven build already runs TestNG tests and generates a testng-results.xml report with custom attributes. Use a JDK compatible with your build.

  • The mapped Test Cases exist and are linked to the intended Jira work item.

  • The Vansah token account has Jira space access and permission to import Test Case results.

  • Read Import TestNG XML Results with the API first. Its single-method parser limitation and PASS/non-PASS mapping also apply to workflow uploads.

The released vansah-action uses a fixed host and older API route without a workspace URL input. The workflow below calls the verified upload directly. Do not add an unsupported URL input to the released Action.

1. Add mappings to your TestNG tests

Add the exact Case Key and Tested Issue custom attributes. Replace the examples with your existing readable keys. This small class demonstrates the mapping structure; use assertions for your own application.

import org.testng.Assert;
import org.testng.annotations.CustomAttribute;
import org.testng.annotations.Test;

public class CheckoutTests {
@Test(attributes = {
@CustomAttribute(name = "Case Key", values = "DEMO-C46"),
@CustomAttribute(name = "Tested Issue", values = "DEMO-123")
})
public void addition() {
Assert.assertEquals(3 + 2, 5);
}

@Test(attributes = {
@CustomAttribute(name = "Case Key", values = "DEMO-C47"),
@CustomAttribute(name = "Tested Issue", values = "DEMO-123")
})
public void subtraction() {
Assert.assertEquals(5 - 2, 3);
}
}

Optional attribute names are Tested Environment, Tested Sprint, and Tested Version. The last one means a Jira release version. The names Test Environment and Test Version are not extracted by the importer.

After running locally, inspect the generated XML to confirm that the attributes are present. A class with only one reported test method can fail in the current parser; do not add artificial tests just to work around that limitation. Use the direct Test Run API for that case.

Example location of testng-results.xml under Maven Surefire reports

2. Configure GitHub values

GitHub setting

Name

Value

Actions secret

VANSAH_TOKEN

Your private Vansah API token.

Actions variable

VANSAH_URL

Workflow environment

JIRA_SPACE_KEY

Your Jira space key; replace DEMO.

Workflow environment

REPORT_PATH

Exact generated report path, not a wildcard.

GitHub repository settings provide Secrets and variables → Actions. Keep the token in a secret. See GitHub’s secret instructions.

3. Add the workflow

Endpoint: POST /api/v2/testCase/import/XML

Save the following as .github/workflows/vansah-testng.yml in your test repository. The example uses Java 17 and a common Surefire report path; adjust both to your build. It runs on manual dispatch so you can review the configuration before enabling other triggers.

name: TestNG results to Vansah
on:
workflow_dispatch:
permissions:
contents: read
jobs:
test:
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v6
- uses: actions/setup-java@v5
with:
distribution: temurin
java-version: '17'
cache: maven
- name: Run TestNG tests
id: tests
continue-on-error: true
run: mvn --batch-mode clean test
- name: Import results to Vansah
if: ${{ !cancelled() }}
shell: bash
env:
VANSAH_URL: ${{ vars.VANSAH_URL }}
VANSAH_TOKEN: ${{ secrets.VANSAH_TOKEN }}
JIRA_SPACE_KEY: DEMO
REPORT_PATH: target/surefire-reports/testng-results.xml
run: |
set -euo pipefail
test -n "$VANSAH_URL"
test -n "$VANSAH_TOKEN"
test -f "$REPORT_PATH"
curl --fail-with-body --silent --show-error \
--request POST \
--url "${VANSAH_URL%/}/api/v2/testCase/import/XML?projectKey=$JIRA_SPACE_KEY" \
--header "Authorization: $VANSAH_TOKEN" \
--header "Accept: application/json" \
--form "testFormat=TestNG" \
--form "testPaths=@$REPORT_PATH;type=application/xml" \
--output vansah-response.json
jq '{success, message, data: {succeedRows: .data.succeedRows, failedRows: .data.failedRows, totalRows: .data.totalRows}}' vansah-response.json
jq -e '.success == true and .data.failedRows == 0 and .data.succeedRows > 0' vansah-response.json
- name: Preserve the test failure
if: ${{ !cancelled() && steps.tests.outcome == 'failure' }}
run: exit 1

The test step is allowed to continue so failed-test results can still be uploaded. The final step makes the job fail again when the tests failed. The import step separately fails for HTTP errors, a failed response, failed rows, or zero imported rows.

Use one exact report file per upload. If you need multiple reports, handle each file explicitly and check each response.

4. Run and verify

  1. Review the mappings, URL, secret, Jira space key, JDK, and report path.

  2. Run the workflow from GitHub Actions.

  3. Check both the test outcome and the import summary. A green upload alone does not mean the application tests passed.

  4. Open the linked Test Cases in Vansah and verify their new runs and results.

If the upload times out, inspect Vansah before rerunning. Reimporting creates additional runs. Read the XML import guide’s error guidance before retrying partial results.

Did this answer your question?