You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/data/markdown/docs/05 Examples/02 Tutorials/01 Get started with k6/100 Test-for-functional-behavior.md
+19-3Lines changed: 19 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -66,13 +66,23 @@ After the test finishes, k6 reports the [default result summary](/results-output
66
66
...
67
67
```
68
68
69
-
To make sure you're getting the right response, you could log the response body to the console as follows:
69
+
As an optional step, you can log the response body to the console to make sure you're getting the right response.
Inspect the console output to determine whether performance crossed a threshold.
94
94
95
95
```
@@ -98,7 +98,7 @@ Inspect the console output to determine whether performance crossed a threshold.
98
98
✗ http_req_failed................: 0.00% ✓ 0 ✗ 1
99
99
```
100
100
101
-
101
+
The ✓ and ✗ symbols indicate whether the performance thresholds passed or failed.
102
102
103
103
## Test performance under increasing load
104
104
@@ -110,7 +110,7 @@ Scenarios schedule load according to the number of VUs, number of iterations, VU
110
110
111
111
### Run a smoke test
112
112
113
-
Start small. Run a [smoke test](/test-types/smoke-testing"a small test to confirm the script works properly") to see your script can handle minimal load.
113
+
Start small. Run a [smoke test](/test-types/smoke-testing"a small test to confirm the script works properly") to check that your script can handle a minimal load.
114
114
115
115
To do so, use the [`--iterations`](/using-k6/k6-options/reference/#iterations) flag with an argument of 10 or fewer.
116
116
@@ -123,15 +123,11 @@ Good thing you ran the test early!
123
123
124
124
### Run a test against an average load
125
125
126
-
Now increase the load.
127
-
128
126
Generally, traffic doesn't arrive all at once.
129
127
Rather, it gradually increases to a peak load.
130
128
To simulate this, testers increase the load in _stages_.
131
129
132
-
Since this is a learning environment, the stages are still quite short.
133
-
Add the following _scenario_ to your options `object` and rerun the test.
134
-
Where the smoke test defined the load in terms of iterations, this configuration uses the [`ramping-vus` executor](/using-k6/scenarios/executors/ramping-vus/) to express load through virtual users and duration.
130
+
Add the following `scenario` property to your `options` object and rerun the test.
135
131
136
132
```javascript
137
133
exportconstoptions= {
@@ -158,6 +154,9 @@ export const options = {
158
154
};
159
155
```
160
156
157
+
Since this is a learning environment, the stages are still quite short.
158
+
Where the smoke test defined the load in terms of iterations, this configuration uses the [`ramping-vus` executor](/using-k6/scenarios/executors/ramping-vus/) to express load through virtual users and duration.
159
+
161
160
Run the test with no command-line flags:
162
161
163
162
```bash
@@ -167,7 +166,6 @@ k6 run api-test.js
167
166
The load is small, so the server should perform within thresholds.
168
167
However, this test server may be under load by many k6 learners, so the results are unpredictable.
@@ -281,13 +278,18 @@ export default function () {
281
278
282
279
</CodeGroup>
283
280
281
+
Run the test.
282
+
283
+
```bash
284
+
k6 run api-test.js
285
+
```
286
+
284
287
Did the threshold fail? If not, add another stage with a higher target and try again. Repeat until the threshold aborts the test:
285
288
286
289
```bash
287
290
ERRO[0010] thresholds on metrics 'http_req_duration, http_req_failed' were breached; at least one has abortOnFail enabled, stopping test prematurely
288
291
```
289
292
290
-
291
293
## Next steps
292
294
293
295
In this tutorial, you used [thresholds](/using-k6/thresholds/) to assert performance and [Scenarios](/using-k6/scenarios) to schedule different load patterns. To learn more about the usual load patterns and their goals, read [Load Test Types](/test-types/load-test-types/)
Collapse file: src/data/markdown/docs/05 Examples/02 Tutorials/01 Get started with k6/300 Analyze results.md
For simplicity to learn about [k6 metric results](/using-k6/metrics/reference/), this tutorial uses the [JSON output](/results-output/real-time/json) and [jq](https://jqlang.github.io/jq/) to filter results.
47
47
48
+
For other options to analyze test results such as storage and time-series visualizations in real-time, check out:
48
49
49
-
For other options to analyze test results such as storage and time-series visualizations in real-time, review:
50
50
- [Results output](/results-output/overview/)
51
51
- [Ways to visualize k6 results](https://k6.io/blog/ways-to-visualize-k6-results/)
52
52
53
-
54
-
55
53
## Write time-series results to a JSON file
56
54
57
-
To output results as JSON lines, use the `--out` flag.
55
+
To output results to a JSON file, use the `--out` flag.
58
56
59
57
```bash
60
58
k6 run --out json=results.json api-test.js
@@ -66,14 +64,13 @@ Then run this `jq` command to filter the latency results; `http_req_duration` me
k6 results have a number of [built-in tags](/using-k6/tags-and-groups/#system-tags).
70
-
For example, filter results to only results where the status is 200:
67
+
k6 results have a number of [built-in tags](/using-k6/tags-and-groups/#system-tags). For example, filter results to only results where the status is 200.
You can also apply [_Tags_](/using-k6/tags-and-groups/#tags) to requests or code blocks.
97
-
To do so:
93
+
You can also apply [_Tags_](/using-k6/tags-and-groups/#tags) to requests or code blocks. For example, this is how you can add a [`tags`](/using-k6/tags-and-groups/#tags) to the [request params](/javascript-api/k6-http/params/).
98
94
99
-
Add a [`tags`](/using-k6/tags-and-groups/#tags) object in the [request params](/javascript-api/k6-http/params/). Give the tag a key and value.
100
-
101
-
```javascript
95
+
```javascript
102
96
const params = {
103
97
headers: {
104
98
"Content-Type": "application/json",
@@ -107,9 +101,9 @@ Add a [`tags`](/using-k6/tags-and-groups/#tags) object in the [request params](/
107
101
"my-custom-tag": "auth-api",
108
102
},
109
103
};
110
-
```
104
+
```
111
105
112
-
Pass `params` to the `http` request. Create the file `tagged-login.js`:
106
+
Create a new script named "tagged-login.js", and add a custom tag to it.
@@ -153,9 +147,8 @@ jq '. | select(.type == "Point" and .metric == "http_req_duration" and .data.tag
153
147
154
148
## Organize requests in groups
155
149
156
-
You can also organize your test logic into [Groups](/using-k6/tags-and-groups#groups), test logic inside a `group` tags to all requests and metrics within its block.
157
-
Groups can help you to organize the test as a series of logical transactions or blocks.
158
-
150
+
You can also organize your test logic into [Groups](/using-k6/tags-and-groups#groups). Test logic inside a `group` tags to all requests and metrics within its block.
151
+
Groups can help you organize the test as a series of logical transactions or blocks.
159
152
160
153
### Context: a new test to group test logic
161
154
@@ -275,8 +268,7 @@ As an example, create a metric that collects latency results for each group:
275
268
1. Create two duration trend metric functions.
276
269
1. In each group, add the `duration`time to the trend for requests to `contacts` and the `coin_flip` endpoints.
0 commit comments