Sitemap

K6 load tests — Part II

3 min readNov 13, 2023

Introducing the configurations file

Press enter or click to view image in full size
https://www.viget.com/articles/styling-native-file-upload-input-field

The below sample test was added in Part I.

import http from 'k6/http';

export default function () {
let res = http.get('http://test.k6.io');
};

Until now, test configurations have been provided as part of the test run command. To configure them in the file create a file load-test-config.json in the same folder and add the configurations below:

{
"vus": 2000,
"iterations": 5000,
"duration": "30s"
}

Run tests with the below command. I should print a similar output as earlier:

k6 run test.js --out json=test.json --config load-test-config.json
Press enter or click to view image in full size

As of now, API call response is not validated. The request might go through but with an invalid response. To validate the response update the test to use the check method.

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

export default function () {
let res = http.get('http://test.k6.io');
check(res, {
'success response': (result) => result.status === 200
})
};

In the test output, before the load test summary, the validation name will be displayed in the green colour, when the assertion is passing.

Press enter or click to view image in full size

To make the assertion fail, update the condition to expect non-success response.

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

export default function () {
let res = http.get('http://test.k6.io');
check(res, {
'failure response': (result) => result.status != 200
})
};
Press enter or click to view image in full size

Multiple assertions can be added to the check method call.

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

export default function () {
let res = http.get('http://test.k6.io');
check(res, {
'success response': (result) => result.status === 200,
'body contains text': (result) => result.body.includes('Collection of simple web-pages suitable for load testing.')
})
};
Press enter or click to view image in full size

In a similar way, more configurations can be added to the config file. Let’s have a look at a few more configurations in Part IV. Before that let’s explore a few options to control stdout logs in Part III.

Note: Subsequent parts of the series are available here.

Happy Testing!

--

--

Kavita Jadhav
Kavita Jadhav

Written by Kavita Jadhav

Application Developer @ Teladoc Health

No responses yet