Smoke testing validates that your test script works and your system performs adequately under minimal load. It’s the first test you should run before any performance testing.
Purpose
Smoke tests help you:
- Verify your test script runs without errors
- Ensure your system handles a small number of virtual users
- Validate test logic and API endpoints
- Catch obvious issues before larger tests
Always run a smoke test before executing load, stress, or soak tests to avoid wasting time on a broken script.
Configuration Pattern
Smoke tests use minimal VUs (1-5) for a short duration (1-5 minutes):
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
vus: 1,
duration: '1m',
thresholds: {
http_req_failed: ['rate<0.01'], // http errors should be less than 1%
http_req_duration: ['p(95)<500'], // 95% of requests should be below 500ms
},
};
export default function() {
const res = http.get('https://quickpizza.grafana.com');
check(res, {
'status is 200': (r) => r.status === 200,
});
sleep(1);
}
Using the Constant VUs Executor
The constant-vus executor maintains a fixed number of VUs:
export const options = {
scenarios: {
smoke: {
executor: 'constant-vus',
vus: 1,
duration: '30s',
},
},
};
Typical Smoke Test Flow
Start with 1 VU
Begin with a single virtual user to validate basic functionality.
Run for short duration
Execute the test for 1-5 minutes to verify stability.
Check for errors
Monitor for script errors, failed requests, and threshold violations.
Validate responses
Ensure API responses contain expected data and status codes.
Best Practices
Use smoke tests as a sanity check in your CI/CD pipeline before running more intensive performance tests.
What to Verify
- Script execution: No JavaScript errors or exceptions
- API availability: All endpoints are accessible
- Response validation: Checks pass successfully
- Basic performance: Response times are reasonable
Example with Multiple Endpoints
import http from 'k6/http';
import { check } from 'k6';
export const options = {
vus: 1,
duration: '2m',
};
export default function() {
// Test multiple endpoints
const responses = http.batch([
['GET', 'https://quickpizza.grafana.com'],
['GET', 'https://quickpizza.grafana.com/api/pizza'],
]);
check(responses[0], {
'homepage status is 200': (r) => r.status === 200,
});
check(responses[1], {
'api status is 200': (r) => r.status === 200,
'api returns json': (r) => r.headers['Content-Type'].includes('application/json'),
});
}
When to Use
- Before every test: Always start with a smoke test
- After script changes: Validate modifications don’t break functionality
- In CI/CD: Quick validation before deploying changes
- New environments: Verify system configuration
Common Issues
If your smoke test fails, fix the issues before running larger tests. Common problems include:
- Incorrect URLs or endpoints
- Authentication failures
- Network connectivity issues
- Missing test data