Performance Testing with K6 Tool

Introduction

k6 is an open-source framework built to make performance testing fun for developers.k6 is written in Goja programming language, which is an implementation of ES2015(ES6) JavaScript on pure Golang language. That means you can use JavaScript to write k6 scripts, although language syntax will only be compatible with the JavaScript ES2015 syntax. Before we proceed to discuss PT using K6 we should first understand what is performance testing.

Performance testing

Testing the stability and response time of the application by applying load is called as Performance Testing.

  • Response time: It is the total time taken to send the request(T1), execute the program(T2), and receive the response(T3)
  • Load: It is nothing but no users.
  • Stability: It is the ability to withstand the load for a designed number of users.

Note. k6 does not run on a Node.js engine. It uses a Go JavaScript compiler.

Installations for k6


Linux

sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 –recv-keysC5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6

MacOS

brew install k6

Windows

choco install k6

Once you have downloaded k6, run the command k6 version on the terminal/command prompt to verify the installation.

Version

To know about all available k6 commands, enter the command k6 help in the terminal/command prompt.

Command prompt

Writing your first performance test script?

Great work! You have installed k6 and know how it works. By now, you must have understood why we should perform load testing on the browser. Now, it’s time to write our first k6 testing script. the first script consists of default virtual users and iterators

import http from 'k6/http';
import {sleep} from 'k6';
export default function () {
  http.get( 'https://test.c-sharpcorner.com/');
  sleep(1);
}  

Output

Output

Conclusion

K6 is a useful tool for checking how well your website or app handles lots of users at once. It helps you find problems and make your site work better. In this article, we tested a URL using default virtual users (VUs) and iterations, and the results showed how well the URL performed.


Similar Articles