Is a smoke test example for basic CRUD functionality using k6 test Api.
The test will do the following
- Creates one new user for all VUs.
- Logins with created user credentials
- Creates new crocodile from the
input-data.json
file. The crocodile number will be selected based on VU index in test. For the 1st user - #1, 5th user - #5, 6th user - #1, #10th user - #5. - Updates created crocodile by Id.
- Deletes crocodile.
Test uses per-vu-interations scenario - vu*interations. Configuration can be found in options.json
file.
"scenarios": {
"simple-iterations": {
"executor": "per-vu-iterations",
"vus": 10,
"iterations": 1,
"maxDuration": "20s"
}
},
Is a load test example from k6 documenation using crocodile get endpoint.
Test uses ramping-vus scenario - users will be added and removed based on stages. Configuration can be found in options.json
file.
"scenarios": {
"rump-up": {
"executor": "ramping-vus",
"startVUs": 1,
"stages": [
{
"duration": "10s",
"target": 10
},
{
"duration": "20s",
"target": 20
},
{
"duration": "5s",
"target": 1
}
],
"gracefulRampDown": "5s"
}
},
For smoke-testing
and load-testing
summary will be added to test_results_summary.json
(in addtion to console log). The detail results will be added in test_results_details.json
.
- Install k6 open source locally for your OS using this link
For Windows
choco install k6
- To run
smoke-testing
orload-testing
sript the following command should be used.
cd smoke-testing
k6 run --config options.json --out json=test_results_details.json script.js
Options can be update in options.json
.
To test basic script in the root folder
k6 run script.js
or with custom options
k6 run --vus 10 --duration 15s script.js
- The results will be available in
test_results_details.json
(in addition to console output)
k6 works with the concept of virtual users (VUs), which run your test scripts. VUs are essentially parallel while(true) loops. Scripts are written in JavaScript, as ES6 modules, so you can break larger tests into smaller pieces or make reusable pieces as you like.
You can ramp the number of VUs up and down during the test. To configure ramping, use the options.stages property.
It is a shortcut option for a single scenario with a ramping VUs executor.
Scenarios configure how VUs and iteration schedules in granular detail. With scenarios, you can model diverse workloads, or traffic patterns in load tests.
Options can be passed in CLI directly
For example set 10 VUs and duration for the test
k6 run --vus 10 --duration 30s script.js
Options also can be create in script code or provided as a separate .json file. We can pass file in CLI or read it inside setup
section in script.
For example
k6 run --config options.json script.js
(see options.json in source code)
All options can be found here
The End-of-test summary can be customized in script.
The results could be expoted in CSV, Json files. Also streaming to cloud supported.
More information about possible results