Learning Notes #77 β Smoke Testing with K6
In this blog, i jot down notes on what is smoke test, how it got its name, and how to approach the same in k6.
The term smoke testing originates from hardware testing, where engineers would power on a circuit or device and check if smoke appeared.

If smoke was detected, it indicated a fundamental issue, and further testing was halted. This concept was later adapted to software engineering.
What is Smoke Testing?
Smoke testing is a subset of test cases executed to verify that the major functionalities of an application work as expected. If a smoke test fails, the build is rejected, preventing further testing of a potentially unstable application. This test helps catch major defects early, saving time and effort.
Key Characteristics
- Ensures that the application is not broken in major areas.
- Runs quickly and is not exhaustive.
- Usually automated as part of a CI/CD pipeline.
Writing a Basic Smoke Test with K6
A basic smoke test using K6 typically checks API endpoints for HTTP 200 responses and acceptable response times.
import http from 'k6/http'; import { check } from 'k6'; export let options = { vus: 1, // 1 virtual user iterations: 5, // Runs the test 5 times }; export default function () { let res = http.get('https://example.com/api/health'); check(res, { 'is status 200': (r) => r.status === 200, 'response time < 500ms': (r) => r.timings.duration < 500, }); }
Advanced Smoke Test Example
import http from 'k6/http'; import { check, sleep } from 'k6'; export let options = { vus: 2, // 2 virtual users iterations: 10, // Runs the test 10 times }; export default function () { let res = http.get('https://example.com/api/login'); check(res, { 'status is 200': (r) => r.status === 200, 'response time < 400ms': (r) => r.timings.duration < 400, }); sleep(1); }
Running and Analyzing Results
Execute the test using
k6 run smoke-test.js
Sample Output
checks...is status 200
response time < 500ms
If any of the checks fail, K6 will report an error, signaling an issue in the application.
Smoke testing with K6 is an effective way to ensure that key functionalities in your application work as expected. By integrating it into your CI/CD pipeline, you can catch major defects early, improve application stability, and streamline your development workflow.