Getting Started with k6

Getting Started with k6

πŸ“… Published: April 2025 β€’ Category: Performance Testing

k6 is an open-source, developer-centric tool designed for load testing and performance testing using JavaScript. It’s scriptable, modern, and integrates well into CI/CD pipelines.

πŸ› οΈ Installation

  • Using Homebrew (Mac): brew install k6
  • Using Chocolatey (Windows): choco install k6
  • Using Docker: docker run -i grafana/k6 run -
  • Or download from the official site.

πŸ§ͺ Writing Your First Script

Expand sample script

// script.js
import http from 'k6/http';
import { check, sleep } from 'k6';

export let options = {
  vus: 10,
  duration: '30s',
};

export default function () {
  let res = http.get('https://test.k6.io');
  check(res, {
    'status was 200': (r) => r.status === 200,
  });
  sleep(1);
}
          

πŸƒ Running the Test

  • Save your script as script.js.
  • Run with: k6 run script.js
  • You’ll see live metrics like requests per second, VUs, and latency.

πŸ“ˆ Viewing Results

k6 outputs real-time CLI metrics including:

  • βœ”οΈ Passed checks
  • ⚑ Response time percentiles (p(95), p(99))
  • πŸ“‰ Throughput (requests/sec)
  • πŸ“Š Error rate and test duration
πŸ’‘ Tip: For enhanced reporting, integrate with k6 Cloud or use output options like JSON, InfluxDB, and Grafana dashboards.

πŸ”š Conclusion

k6 makes it easy for developers and testers to collaborate on performance testing. Its code-first approach, clean output, and CI/CD integrations make it ideal for modern DevOps workflows.

Try extending your script with thresholds, custom metrics, or load profiles next!