Menu
Documentationbreadcrumb arrow Grafana k6breadcrumb arrow Using k6breadcrumb arrow Run a k6 test script
Open source

Run a k6 test script

There are several ways you can use the Grafana k6 command-line tool (CLI) to run a k6 performance test. In this page, you’ll learn how to use each method and how they differ from each other.

Before you begin

To run a CLI test, you’ll need:

Run a test on your local machine

Running tests locally is a great way to incrementally test your script as you write it. For example, you can make sure that your checks and thresholds are configured correctly before you run a test with more VUs in Grafana Cloud k6.

To run a test locally, use the k6 run command:

Bash
k6 run script.js

Run a test using Grafana Cloud k6

Grafana Cloud k6 is a performance testing application that’s part of Grafana Cloud, and it’s powered by k6 OSS. It allows you to leverage all of the Grafana k6 OSS capabilities while managing the infrastructure needed for scaling servers, running load tests from multiple locations, storing test results, and providing dashboards to detect performance errors and regressions.

Grafana Cloud k6 makes it easier to visualize and compare test results by providing you with built-in dashboards, while also making it easier to share and collaborate on test data with other teams in your organization.

To run a cloud test from the CLI, you’ll need an API token for authenticating the k6 CLI with the Grafana Cloud k6 application.

After you retrieve an API token, you can authenticate with the CLI by running the following command:

Bash
k6 cloud login --token <API_TOKEN>

With the CLI authentication configured, you can run cloud tests by using the k6 cloud command:

Bash
k6 cloud run cloud_demo.js

You can also run a test from a local machine and stream the results for storage and visualization on Grafana Cloud. A common use case for this feature is to run load tests in a CI/CD environment, or on networks that aren’t accessible from the public internet.

To run a test locally and stream the results to Grafana Cloud k6, use the k6 cloud run --local-execution:

Bash
k6 cloud run --local-execution cloud_demo.js

Note

The k6 cloud run --local-execution command uploads the test archive k6 produces from your test script and resources to Grafana Cloud.

You can change this behavior by adding the --no-archive-upload option to your command. For example: k6 cloud run --local-execution --no-archive-upload script.js.

To learn more about Grafana Cloud k6, refer to:

Run a test in your infrastructure with the k6 Operator

k6 Operator is a Kubernetes operator that you can use to run distributed k6 tests in your Kubernetes cluster.

A couple of reasons why you might want to do this:

  • You run your application in Kubernetes and would like k6 to be executed in the same fashion as all your other infrastructure components.
  • You want to run your tests within your private network for security or privacy reasons.

To set up and run a test using the k6 Operator, refer to Set up distributed k6.