How to Perform API Load Testing from Command Line Using k6 CLI?

Asked -12 seconds ago Updated 2 hours ago 15 views

0

k6 is an open-source load testing tool designed for developer happiness and performance testing in CLI environments. It uses JavaScript to define test scenarios.

How to write and run an API load test using k6 CLI?

Follow these steps to execute a performance test from the terminal:

1. Create a Test Script (script.js)

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

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

export default function () {
    const res = http.get('https://api.example.com/v1/health');
    check(res, {
        'status is 200': (r) => r.status === 200,
    });
    sleep(1);
}

2. Execute via Command Prompt

k6 run script.js

The CLI output displays real-time metrics including HTTP request duration, failure rate, and request volume per second.

0 Answers


Write Your Answer