Stress Testing
What is Stress Testing?
Stress testing pushes the application beyond its normal operational capacity to identify its breaking point and how gracefully it fails or recovers.
Key Aspects Verified
- The application's behaviour when resources are exhausted (CPU, memory, bandwidth).
- Whether the system fails gracefully or crashes catastrophically under extreme load.
- How well the system recovers once the stress condition is removed.
Load vs Stress Testing
Load testing verifies performance under expected conditions, while stress testing deliberately exceeds those conditions to find the system's limits.
Running a Stress Test, Step by Step
- Know the normal load. Find out the expected number of users or requests from analytics or requirements. You cannot go "beyond normal" without knowing what normal is.
- Pick the critical journeys. Login, search and checkout usually matter more than rarely used pages.
- Prepare an isolated environment. Use a production-like setup, not production itself, unless the business has formally approved a controlled test window.
- Ramp up in stages. Increase load gradually past the expected peak until errors or response times become unacceptable.
- Hold, then remove the load. Watch how the system behaves at the edge and how quickly it returns to normal afterwards.
- Analyse and report. Record the breaking point, the first component to fail, and the recovery time.
A Sample Script with k6
k6 is an open-source load testing tool where scenarios are written in JavaScript. The stages below climb well past an assumed normal load, then drop to zero to observe recovery.
import http from 'k6/http';
import { check, sleep } from 'k6';
export const options = {
stages: [
{ duration: '2m', target: 100 }, // normal load
{ duration: '3m', target: 300 }, // above normal
{ duration: '3m', target: 600 }, // well beyond expected peak
{ duration: '2m', target: 0 }, // remove load, watch recovery
],
};
export default function () {
const res = http.get('https://staging.example.com/products');
check(res, { 'status is 200': (r) => r.status === 200 });
sleep(1);
}
Run it with k6 run stress.js. Apache JMeter, Gatling and Locust can model the same pattern if your team already uses them.
What to Measure and How to Read It
- Error rate: the load level where errors start climbing is often the practical breaking point.
- Response time percentiles: the 95th or 99th percentile shows what slow users experience, which averages hide.
- Server resources: CPU, memory, disk I/O, open connections and thread pools on every tier.
- Database behaviour: lock waits, slow queries and connection pool exhaustion.
- Recovery: time taken for response times and error rates to return to normal once load drops.
A good outcome is not "the system never fails". It is a system that slows down or rejects extra requests politely, shows clear error messages, keeps data consistent and recovers without manual restarts.
Stress Testing Compared with Related Tests
| Test type | Load pattern | Question it answers |
|---|---|---|
| Load | Expected peak | Does it meet targets under normal busy conditions? |
| Stress | Beyond peak until failure | Where does it break, and how does it recover? |
| Spike | Sudden jump | Can it survive a sudden rush, such as a sale launch? |
| Soak | Steady load for hours | Do memory leaks or slow degradation appear over time? |
Common mistakes include testing from one weak load generator that becomes the bottleneck itself, ignoring caches that make results look better than reality, and forgetting to warn infrastructure or security teams before generating heavy traffic.
Ready to master real-world software testing?
Learn manual and automation testing hands-on with mentor-led sessions.