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!