1.0.0 • Published 3 months ago
k6-test-framework v1.0.0
Load Testing Framework with k6
Installation (Ubuntu/Linux)
- Node.js & npm:
curl -fsSL https://deb.nodesource.com/setup_20.x | sudo -E bash -
sudo apt-get install -y nodejs
- k6:
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6
- Project Dependencies:
npm install
Running Tests
# Example smoke test
BASE_URL=https://api.yoursite.com npm run test:smoke
# Full test suite
npm run test:smoke && npm run test:stress && npm run test:soak
Reports
HTML reports auto-generate in reports/
directory after each test run.
Running Tests from Dockerfile
- Build Docker Image
docker build -t k6-reqres .
- Run Tests Inside Docker:
sudo docker run -it --rm -v $(pwd)/reports:/app/reports -e BASE_URL=https://reqres.in/api -e TEST_TYPE=smoke k6-reqres run tests/smoke.test.js
Running Tests from Docker Compose
- Specify the test name in the terminal while running tests.
./run-test.sh smoke # For Smoke test
./run-test.sh stress # For Stress test
./run-test.sh soak # For Soak test
Adapting to Other Websites
To use this framework with different systems, modify:
API Endpoints:
- Update endpoints in
api/*.js
files - Modify request payloads in test files
- Update endpoints in
Environment Config:
- Update
config/global.js
with new base URLs - Adjust thresholds in
config/thresholds.js
- Update
Test Parameters:
- Modify virtual users and duration in test files'
options
- Update workflow stages in
config/workflowOptions.js
- Modify virtual users and duration in test files'
Data Generation:
- Customize mock data templates in
utils/dataGeneration.js
- Customize mock data templates in
Assertions:
- Update response validation checks in test files
- Modify schema validations in
config/constants.js
Maintenance
- Review reports in
reports/
directory - Monitor test thresholds in
config/thresholds.js
- Update rate limiting rules in
api/rateLimiter.js
1.0.0
3 months ago