|
1 | 1 | ---
|
2 | 2 | title: "Smoke testing"
|
3 | 3 | head_title: 'What is Smoke Testing? How to create a Smoke Test in k6'
|
4 |
| -excerpt: "Smoke test is a regular load test, configured for minimal load. You want to run a smoke test as a sanity check every time you write a new |
5 |
| -script or modify an existing script. Let’s see an example." |
| 4 | +excerpt: "A Smoke test is a minimal load test to run when you create or modify a script." |
6 | 5 | ---
|
7 | 6 |
|
8 |
| -A smoke test is a test configured for minimal load. |
| 7 | +Smoke tests have a minimal load. |
| 8 | +Run them to verify that the script works well, the system functions under minimal load, and to gather baseline performance values. |
9 | 9 |
|
10 |
| -Each time you write a new test script, it's a good idea to run a smoke to test first, which helps you: |
11 |
| -- Verify that your test script doesn't have errors. |
12 |
| -- Verify that your system doesn't throw any errors when under minimal load. |
| 10 | +This test type consists of running tests with only one or a few VUs. Keep the number to 5 VUs or less. |
| 11 | +Exceeding 5 could turn the test into a mini-load test. |
| 12 | +Similarly, the test shouldn't have many iterations. 3 to 10 iterations should be enough (or an iteration duration with a short period). |
13 | 13 |
|
14 |
| -## Smoke testing in k6 |
| 14 | + |
15 | 15 |
|
16 |
| -The following script is a sample smoke test script to get you started. |
17 |
| -You can copy it, change the end points, and start testing. |
18 |
| -If you'd like to see more comprehensive script, check out our [example section](/examples). |
| 16 | +In some testing conversation, smoke tests are also called shakeout tests. |
19 | 17 |
|
20 |
| -<CodeGroup labels={["sample-smoke-test.js"]} lineNumbers={[true]} heightTogglers={[true]}> |
| 18 | +## When to run a Smoke test |
21 | 19 |
|
22 |
| -```javascript |
23 |
| -import http from 'k6/http'; |
24 |
| -import { check, group, sleep, fail } from 'k6'; |
| 20 | +Teams should run smoke tests whenever a test script is created or updated. Smoke testing should also be done every time the application code is updated. |
25 | 21 |
|
26 |
| -export const options = { |
27 |
| - vus: 1, // 1 user looping for 1 minute |
28 |
| - duration: '1m', |
| 22 | +It's a good practice to run a smoke test as a first step, with the following goals: |
29 | 23 |
|
30 |
| - thresholds: { |
31 |
| - http_req_duration: ['p(99)<1500'], // 99% of requests must complete below 1.5s |
32 |
| - }, |
33 |
| -}; |
| 24 | +- Verify that your test script doesn't have errors. |
| 25 | +- Verify that your system doesn't throw any errors (performance or system related) when under minimal load. |
| 26 | +- Gather baseline performance metrics of your system’s response under minimal load. |
| 27 | +- With simple logic, to serve as a synthetic test to monitor the performance and availability of production environments. |
34 | 28 |
|
35 |
| -const BASE_URL = 'https://test-api.k6.io'; |
36 |
| -const USERNAME = 'TestUser'; |
37 |
| -const PASSWORD = 'SuperCroc2020'; |
| 29 | +## Considerations |
| 30 | + |
| 31 | +When you prepare a smoke test, consider the following: |
38 | 32 |
|
39 |
| -export default () => { |
40 |
| - const loginRes = http.post(`${BASE_URL}/auth/token/login/`, { |
41 |
| - username: USERNAME, |
42 |
| - password: PASSWORD, |
43 |
| - }); |
44 | 33 |
|
45 |
| - check(loginRes, { |
46 |
| - 'logged in successfully': (resp) => resp.json('access') !== '', |
47 |
| - }); |
| 34 | +- **Each time you create or update a script, run a smoke test** |
48 | 35 |
|
49 |
| - const authHeaders = { |
50 |
| - headers: { |
51 |
| - Authorization: `Bearer ${loginRes.json('access')}`, |
52 |
| - }, |
53 |
| - }; |
| 36 | + Because smoke tests verify test scripts, try to run one every time you create or update a script. Avoid running other test types with untested scripts. |
| 37 | + |
| 38 | +- **Keep throughput small and duration short** |
| 39 | + |
| 40 | + Configure your test script to be executed by a small number of VUs (from 2 to 5) with few iterations (3 to 10) or brief durations (30 to 60 seconds). |
| 41 | + |
| 42 | +## Smoke testing in k6 |
54 | 43 |
|
55 |
| - const myObjects = http.get(`${BASE_URL}/my/crocodiles/`, authHeaders).json(); |
56 |
| - check(myObjects, { 'retrieved crocodiles': (obj) => obj.length > 0 }); |
| 44 | +<CodeGroup labels={["smoke.js"]} lineNumbers={[]} showCopyButton={[true]}> |
57 | 45 |
|
| 46 | +```javascript |
| 47 | +import http from 'k6/http'; |
| 48 | +import { check, sleep} from 'k6'; |
| 49 | + |
| 50 | +export const options = { |
| 51 | + vus: 3, // Key for Smoke test. Keep it at 2, 3, max 5 VUs |
| 52 | + duration: '1m', // This can be shorter or just a few iterations |
| 53 | +}; |
| 54 | + |
| 55 | +export default () => { |
| 56 | + const urlRes = http.req('https://test-api.k6.io'); |
58 | 57 | sleep(1);
|
| 58 | + // MORE STEPS |
| 59 | + // Here you can have more steps or complex script |
| 60 | + // Step1 |
| 61 | + // Step2 |
| 62 | + // etc. |
59 | 63 | };
|
60 | 64 | ```
|
61 | 65 |
|
62 | 66 | </CodeGroup>
|
63 | 67 |
|
64 |
| -The VU chart of a smoke test should look similar to this. |
65 |
| -You want to use only 1 or 2 VUs. |
66 |
| - |
67 | 68 |
|
68 |
| -If your smoke test produces any errors, |
69 |
| -you should either correct the script or fix your environment before you continue. |
| 69 | +The following script is an example smoke test. You can copy it, change the endpoints, and start testing. For more comprehensive test logic, refer to [Examples](/examples). |
| 70 | +The VU chart of a smoke test should look similar to this. Again, a smoke test should use only 2 or 3 VUs and run for only a brief period. |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | +## Results analysis |
| 75 | + |
| 76 | +The smoke test initially validates that your script runs without errors. If any script-related errors appear, correct the script before trying any more extensive tests. |
| 77 | + |
| 78 | +On the other hand, if you notice poor performance with these low VU numbers, report it, fix your environment, and try again with a smoke test before any further tests. |
70 | 79 |
|
71 |
| -The k6 output should look similar to this: |
72 |
| - |
| 80 | +Once your smoke test shows zero errors and the performance results seem acceptable, you can proceed to other test types. |
73 | 81 |
|
74 |
| -Once your smoke test shows zero errors, you can go to the next step and execute a [load test](/test-types/load-testing) to assess the performance of your system. |
|
0 commit comments