When a test finishes, k6 prints an end-of-test summary to stdout, providing top-level details about the test run.
If the default report doesn't suit you, you can use the handleSummary() function to completely customize output (including format).
The default summary
The end-of-test summary reports details and aggregated statistics for the primary aspects of the test:
- Summary statistics about each built-in and custom metric (e.g. mean, median, p95, etc).
- A list of the test's groups and scenarios
- The pass/fail results of the test's thresholds and checks.
You can use options to configure or silence the report.
End-of-test example
Here's an example of a report that k6 generated after a test run.
- It has a scenario, Ramp_Up
- The requests are split into two groups:
- GET home, which has a check that responses are 200 (all passed)
- Create resource, which has a check that responses are 201 (all failed)
- The test has one threshold, requiring that 95% of requests have a duration under 200ms (failed)
Customize with handleSummary()
Use the handleSummary() function to completely customize the end-of-test summary report.
k6 callshandleSummary() at the end of the test run, even after teardown(). If handleSummary() is exported, k6 does not print the default summary.
Besides customizing the CLI summary, you can also transform the summary data into machine- or human-readable formats. This lets you create JS-helper functions that generate JSON, CSV, XML (JUnit/xUnit/etc.), HTML, etc. files from the summary data.
Note: For now, the handleSummary() feature is available only for local k6 run tests. However we plan to support the feature for k6 Cloud tests eventually. You can track progress in this issue.
Data format returned by handleSummary()
k6 expects handleSummary() to return a {key1: value1, key2: value2, ...} map that represents the summary-report content. While the values can have a type of either string or ArrayBuffer, the keys must be strings.
The keys determine where k6 displays or saves the content:
- stdout for standard output
- stderr for standard error,
- any relative or absolute path to a file on the system (this operation overwrites existing files)
To get an idea how data would look in your specific test run, just add return { 'raw-data.json': JSON.stringify(data)}; in your handleSummary() function and inspect the resulting raw-data.json file. Here's a very abridged example of how it might look:
Send reports to a remote server
You can also send the generated reports to a remote server by making an HTTP request (or using any of the other protocols k6 already supports)! Here's a simple example:
The preceding snippet uses some JS helper functions to transform the summary in various formats. These helper functions might change, so keep an eye on jslib.k6.io for the latest.
Of course, we always welcome PRs to the jslib, too!
Custom output examples
These examples are community contributions. We thank everyone who has shared!
- Using the JUnit output with Azure Test Plan
- Using the JUnit output with TestRail
- handleSummary and custom Slack integration
- Reporting to Xray
- HTML reporter
Summary options
k6 provides some options to filter or silence summary output:
- The --summary-trend-stats option defines which Trend metric statistics to calculate and show.
- The --summary-time-unit option forces k6 to use a fixed-time unit for all time values in the summary.
- The --no-summary option completely disables report generation, including --summary-export and handleSummary().
- The --summary-export option exports a summary report with a predefined JSON format to a file. Now discouraged; use the handleSummary callback instead.
Summary export to a JSON file
k6 also has the --summary-export=path/to/file.json option, which exports some summary report data to a JSON file.
The format of --summary-export is similar to the data parameter of the handleSummary() function. Unfortunately, the --summary-export format is limited and has a few confusing peculiarities. For example, groups and checks are unordered, and threshold values are unintuitive: true indicates the threshold failed, and false that it succeeded.
We couldn't change the --summary-export data format, because it would have broken backward compatibility in a feature that people depended on in CI pipelines. But, the recommended approach to export to a JSON file is the handleSummary() callback. The --summary-export option will likely be deprecated in the future.