2/10/2026

How to Integrate k6 with Xray/Jira

 

Automated Testing in Jira with Xray | Atlassian

How to Integrate k6 with Xray/Jira

Tags: k6, xray, jira, javascript, performance-testing, automation

Performance testing is a critical part of delivering scalable and reliable APIs. In this article, I’ll walk you through a simple and practical way to integrate k6 performance test results with Xray in Jira.


Why We Chose k6

Some time ago, I was assigned the task of writing a performance test for an API expected to handle a large number of requests. We needed a tool that was:

  • Easy to learn

  • Quick to implement

  • Friendly for QA engineers to contribute to

Having previously used Load Impact, I was already familiar with k6, which made it a natural choice.

Here are the main reasons we selected k6:

1. JavaScript-Based

Most QA engineers and developers on the team were already familiar with JavaScript. This eliminated the need to learn a new programming language.

2. Open Source

k6 is completely open-source. No licensing costs, and it has a very active community.

3. CI/CD Friendly

Integrating k6 into our CI/CD pipeline was straightforward and seamless.

There are many more advantages to using k6, but I’ll cover those in a separate post.


The Challenge: Sending k6 Results to Xray/Jira

After completing our performance test framework, we wanted our test results available in Jira via Xray.

Since we were already using Xray for test management, we needed a way to convert the k6 JSON report into a format compatible with Xray.

At the time, I couldn’t find a solution that worked for our specific case — so I built one.

Fortunately, k6 provides a powerful function called:

handleSummary() in k6

The handleSummary() function allows you to generate custom summary reports after a load test completes.

It gives you access to all test metrics and lets you:

  • Format the data

  • Export it as JSON

  • Print to stdout

  • Generate XML

  • Save to files

This flexibility made it possible to transform k6 results into an Xray-compatible JSON format.


The Solution: k6 → Xray JSON Converter

I created a helper script that:

  1. Takes the data object from handleSummary()

  2. Converts it into Xray’s required JSON structure

  3. Outputs a summary.json file

  4. Allows importing results into Xray

You can clone the repository here:

git clone https://github.com/skingori/k6-json-xray.git

Project Structure Recommendation

Inside your main project, create something like:

/helper /src /report

Place generator.js inside the helper folder to keep imports organized.


Prerequisites

Make sure you have the following installed:

  • Node.js

  • npm

  • k6


How It Works

If your k6 tests are organized in groups, and each group name corresponds to an Xray Test Case key, the script will automatically map the results.

For example, in Xray you may have test cases:

  • CALC-01

  • CALC-02

In your k6 test:

group('CALC-01', function() { // test code }); group('CALC-02', function() { // test code });

The script searches for these group names and assigns the test results to the matching Xray test cases.


How to Configure handleSummary()

First, import the required modules:

import { getSummary } from "./generator.js"; import { textSummary } from "https://jslib.k6.io/k6-summary/0.0.1/index.js";

If your file is inside a helper folder:

import { getSummary } from "./helper/generator.js";

Now, add the handleSummary() function at the end of your test script:

export function handleSummary(data) { return { stdout: textSummary(data, { indent: " ", enableColors: true }), "summary.json": JSON.stringify(getSummary(data, "CALC-2062", "CALC"), null, 2) }; }

What This Does

  • textSummary() → Prints a readable report to the console

  • getSummary() → Converts k6 data into Xray format

  • summary.json → Saves the formatted result

If you don’t need console output, you can remove the stdout line.


Complete Example Script

import http from 'k6/http'; import { sleep, group, check } from 'k6'; import { getSummary } from "./generator.js"; import { textSummary } from "https://jslib.k6.io/k6-summary/0.0.1/index.js"; export const options = { vus: 10, duration: '30s', }; export default function() { group('CALC-01', function() { const resp = http.get('http://test.k6.io'); check(resp, { 'status is 200': (r) => r.status === 200, }); sleep(1); }); group('CALC-02', function() { const resp = http.get('http://test.k6.io'); check(resp, { 'status is 200': (r) => r.status === 200, }); sleep(1); }); }; export function handleSummary(data) { return { stdout: textSummary(data, { indent: " ", enableColors: true }), "summary.json": JSON.stringify(getSummary(data, "CALC-2062", "CALC"), null, 2) }; }

Running the Script

Execute your test with:

k6 run script.js -e TEST_PLAN_KEY="CALC-2345" -e TEST_EXEC_KEY="CALC-0009"

What These Keys Mean

  • TEST_PLAN_KEY → Identifies the Xray Test Plan

  • TEST_EXEC_KEY → Identifies the Test Execution issue in Jira

These keys allow Xray to correctly associate the results.


Example Output (summary.json)

{ "info": { "summary": "K6 Test execution - Mon Sep 09 2024 21:20:16 GMT+0300 (EAT)", "description": "This is a k6 test with a maximum iteration duration of 4.95s, 198 passed requests and 0 failures on checks", "user": "k6-user", "startDate": "2024-09-09T18:20:16.000Z", "finishDate": "2024-09-09T18:20:16.000Z", "testPlanKey": "CALC-2345" }, "testExecutionKey": "CALC-0009", "tests": [ { "testKey": "CALC-01", "start": "2024-09-09T18:20:16.000Z", "finish": "2024-09-09T18:20:16.000Z", "comment": "Test execution passed", "status": "PASSED" }, { "testKey": "CALC-02", "start": "2024-09-09T18:20:16.000Z", "finish": "2024-09-09T18:20:16.000Z", "comment": "Test execution passed", "status": "PASSED" } ] }

This JSON file can now be imported directly into Xray.


Final Thoughts

By leveraging k6’s handleSummary() function, you can easily customize performance test outputs and integrate them into tools like Xray/Jira.

This approach allows you to:

  • Keep performance testing within k6

  • Maintain JavaScript consistency

  • Seamlessly integrate with Jira workflows

  • Automate reporting in CI/CD

If you’re using Xray and k6 together, this solution provides a simple and scalable way to bridge the gap.

Niciun comentariu:

K6 links

 K6 links GitHub - Xray-App/tutorial-js-k6 How to integrate k6 with Xray/Jira - DEV Community Non-Functional Testing: Load and Stress Tests ...