Use the Vansah Java binding to record results from your Java test automation in Vansah. Add VansahNode.java to your project, configure the connection and call its methods as your tests run.
The binding can create Test Runs against Jira work items, Test Folders, Standard Test Plans or Advanced Test Plans. It also records step results and screenshots, or a single overall result through a Quick Test.
Before you begin
Install Vansah Test Management for Jira and create the Test Cases you want to report against.
Create a Vansah API token and find your site’s API Connect URL.
Have your Jira space key and the destination work item, folder or plan details.
Use Java JDK 8 or newer. The examples below use Maven, matching the binding repository.
Your account must be able to execute the tests. For a plan, the Test Case must be in the intended requirement and the selected iteration must already exist.
1. Add the dependencies and binding
Add the two binding dependencies to your pom.xml. If it already has a dependencies section, add these entries inside that section:
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>com.mashape.unirest</groupId>
<artifactId>unirest-java</artifactId>
<version>1.4.9</version>
</dependency>
</dependencies>
These versions match the current binding repository’s pom.xml. Follow your project’s dependency management process when integrating them.
Download VansahNode.java from the official repository and place it in the matching com.vansah package in your project. The current binding uses Vansah API v2.
2. Configure the connection
Provide the token through your environment or pipeline’s secret store. This setup reads VANSAH_TOKEN, VANSAH_URL and VANSAH_PROJECT_KEY:
import com.vansah.VansahNode;
import java.io.File;
// Put this setup in your test initialization.
VansahNode app = new VansahNode();
VansahNode.setVansahToken(System.getenv("VANSAH_TOKEN"));
VansahNode.setVansahURL(System.getenv("VANSAH_URL"));
VansahNode.setProjectKey(System.getenv("VANSAH_PROJECT_KEY"));
The Jira space key identifies the space, for example DEMO. Use the base API Connect URL shown in Vansah settings; the binding adds the API path.
Optional properties can be set before creating the run:
app.setENVIRONMENT_NAME("UAT");
app.setSPRINT_NAME("Sprint 1");
app.setRELEASE_NAME("Release 1");Place execution and logging calls inside your test methods. Some methods declare checked exceptions, so handle them or declare them in your test method as appropriate for your framework.
3. Choose where to create the Test Run
Choose one destination for each run. Replace the sample keys and paths with your own records. Use the same instance to record the run’s step results.
Jira work item
app.setJIRA_ISSUE_KEY("DEMO-9");
app.addTestRunFromJIRAIssue("DEMO-C50");
Test Folder
app.setFOLDERPATH("regression/login/");
app.addTestRunFromTestFolder("DEMO-C50");The path must contain / and must not start with /. See Getting the folder path of a Test Folder.
Standard Test Plan
app.setStandardTestPlanKey("DEMO-P2");
app.setTestPlanIteration(2);
app.addTestRunFromStandardTestPlan("DEMO-C50");
Advanced Test Plan
Set the plan and the requirement within it. For a Jira work item requirement:
app.setAdvancedTestPlanKey("DEMO-P1");
app.setTestPlanIteration(2);
app.setJIRA_ISSUE_KEY("DEMO-9");
app.addTestRunFromAdvancedTestPlan("issue", "DEMO-C50");For a folder requirement, set its folder path and use "folder":
app.setFOLDERPATH("regression/login/");
app.addTestRunFromAdvancedTestPlan("folder", "DEMO-C50");
Iteration behavior: Test Plan runs default to iteration 1. This Java binding accepts integers 1 through 5 in setTestPlanIteration. Call it before creating the run. This range is a binding limitation, not the total number of iterations Vansah can hold. The setting does not affect work item or folder runs.
4. Record the result for each step
After your automation performs a step, call addTestLog with its actual result, a comment and the matching Test Case step number. Step numbers start at 1.
app.addTestLog("passed", "The sign-in form opened.", 1);
app.addTestLog("failed", "The confirmation message did not appear.", 2);The run starts as Untested. The binding updates the matching step logs as you submit results. Record the outcomes your automation actually observed.
Result name | Numeric value |
| 0 — N/A |
| 1 — Failed |
| 2 — Passed |
| 3 — Untested |
Names are case-insensitive. Use NA for N/A. Unknown strings fall back to N/A in the current binding, so avoid arbitrary result names.
5. Attach a screenshot or update the latest log
Pass a java.io.File as the fourth argument to addTestLog:
File screenshot = new File("target/screenshots/confirmation.png");
app.addTestLog("failed", "The confirmation message did not appear.", 2, screenshot);The file must exist on the machine running the test. To revise the most recently recorded log, use updateTestLog:
File recheck = new File("target/screenshots/recheck.png");
app.updateTestLog("failed", "Rechecked: the confirmation message is still missing.", recheck);
Record one overall result with a Quick Test
For a Jira work item result with no step-by-step reporting, use a numeric result value:
app.setJIRA_ISSUE_KEY("DEMO-9");
app.addQuickTestFromJiraIssue("DEMO-C50", 2); // 2 = PassedFor a Test Folder, set its path and call addQuickTestFromTestFolders. A Quick Test creates the run and records its overall result in one call.
Useful methods
Method | Purpose |
| Record a step result. An optional fourth argument supplies a screenshot File. |
| Revise the latest log. An optional third argument supplies a screenshot File. |
| Delete the current run stored by the instance. |
| Delete the current log. When its step is known, the binding restores an Untested entry. |
| Print outgoing request details for troubleshooting. |
Troubleshooting
Problem | What to check |
Missing class or dependency | Check the com.vansah package location, import and Maven dependencies. |
Method cannot be found | Use the exact capitalization shown here. For example, the run method is |
Run or log does not appear | Check the console response, token, API URL, Jira space key and permissions. Create the run successfully before recording logs. |
Plan or iteration error | Confirm that the case is in the selected plan requirement and the iteration exists. This binding accepts iteration numbers 1–5. |
Screenshot is missing | Pass a File that exists on the test runner, rather than a workstation-only path. |
Enable request logging with VansahNode.setDebug(true); or VANSAH_DEBUG=true. Review logs for sensitive test data before sharing them.
Check the saved results
Open the destination work item, Test Folder or Test Plan in Vansah. For a plan, select the relevant iteration. Review the Test Run, step results, comments and attachments.
More help
See the official Java binding repository for the latest class and examples. For report uploads from a pipeline, see Sending Automated Test Results to Vansah from CI/CD.
