Run your k6 test locally

In this milestone, you run your k6 test script locally on your machine. Running tests locally allows you to quickly iterate on your scripts and see immediate results without requiring cloud infrastructure.

When you run a k6 test, it executes the default function the number of times specified in your options, collects performance metrics, and displays a summary of the results in your terminal. The results include information about HTTP requests, response times, data transfer, and any errors encountered during the test.

To run your k6 test locally, complete the following steps:

  1. Open your terminal and navigate to the directory containing your script.js file.

  2. Run the k6 test using the following command:

    Bash
    k6 run script.js

    If you’re using Docker instead of a native installation, run the command from the directory that contains script.js (the < passes the script into the container):

    Bash
    docker run --rm -i grafana/k6 run - < script.js
  3. Observe the test execution in your terminal. k6 displays real-time information about the test progress, including:

    • Current iteration count
    • HTTP request statistics
    • Response time metrics
    • Data transfer information
    • Any errors or failures
  4. Review the test summary that appears when the test completes. The summary includes:

    • Total test duration
    • Number of iterations completed
    • HTTP request statistics (total requests, successful requests, failed requests)
    • Response time metrics (average, minimum, maximum, p90, p95 — where p95 means 95% of requests were faster than this value)
    • Data transfer metrics (data sent, data received)
    • Checks and thresholds status (if configured)

    You should see output similar to:

    text
    TOTAL RESULTS
    
     checks_total.......................: 10      13.122179/s
     checks_succeeded...................: 100.00% 10 out of 10
     checks_failed......................: 0.00%   0 out of 10
    
     ✓ status was 200
    
     HTTP
     http_req_duration..............: avg=123.45ms min=98.12ms med=120.00ms max=156.78ms

p(90)=148ms p(95)=150ms http_req_failed…………….: 0.00% 0 out of 10 http_reqs………………….: 10 1.67/s

EXECUTION
iteration_duration.............: avg=1.12s min=1.10s med=1.11s max=1.15s p(90)=1.14s

p(95)=1.14s iterations…………………: 10 1.67/s

NETWORK
data_received..................: 15 kB  2.5 kB/s
data_sent......................: 1.0 kB 168 B/s

If the test fails to run or you encounter errors, check that your script syntax is correct and that you have network connectivity to the target URL. For more help, refer to the k6 documentation on running tests.

In the next milestone, you’ll send these test results to Grafana Cloud to visualize them in dashboards and analyze performance trends over time.


page 5 of 8