firmanrosid / performance-testing-with-k6

Performance testing with k6

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

k6

Like unit testing, for performance

A modern load testing tool for developers and testers in the DevOps era.


---


k6 is a modern load testing tool, building on our years of experience in the load and performance testing industry. It provides a clean, approachable scripting API, local and cloud execution, and flexible configuration.

Install

Mac

Install with Homebrew by running:

brew install k6

Windows

If you use the Chocolatey package manager you can install the unofficial k6 package with:

choco install k6

Running k6

k6 works with the concept of virtual users (VUs) that execute scripts - they're essentially glorified, parallel while(true) loops. Scripts are written using JavaScript as ES6 modules, which allows you to break larger tests into smaller and more reusable pieces, making it easy to scale tests across an organization.

Scripts must contain, at the very least, an exported default function - this defines the entry point for your VUs, similar to the main() function in many languages. Let's create a very simple script that makes an HTTP GET request to a test website:

import http from "k6/http";
export default function() {
    let response = http.get("https://reqres.in/api/users");
};

The script details and how we can extend and configure it will be explained below, but for now, simply save the above snippet as a listUser.js file somewhere on your system. Assuming that you've installed k6 correctly, on Linux and Mac, you can run the saved script by executing k6 run listUser.js from the same folder. For Windows, the command is almost the same - k6.exe run listUser.js.

About

Performance testing with k6


Languages

Language:JavaScript 100.0%