K6 API Performance Framework
This repository provides a simple and extensible API performance testing framework using k6. It is designed to help teams automate, run, and analyze performance tests for RESTful APIs with ease.
Features
- Modular structure for easy test management
- Custom metrics and reporting
- Example test cases and data-driven testing
- HTML and JSON reports for results analysis
- Utility helpers for HTTP requests and configuration
Project Structure
k6-api-tests/
├── data/ # Test data (e.g., users.json)
├── modules/ # Helper modules (config, HTTP helpers)
├── reports/ # Generated reports (HTML, JSON)
├── scripts/ # Shell scripts for running tests
├── tests/ # Test definitions (e.g., user.test.js)
└── utils/ # Custom metrics and utilities
Getting Started
Prerequisites
- k6 installed (v0.34.0 or later)
- Node.js (for report generation scripts)
Install Dependencies
Install Node.js dependencies:
cd k6-api-test
npm install
Install simple-statistics for HTML report generation:
npm install simple-statistics
Running Tests
-
Run the k6 Test:
k6 run tests/user.test.js --summary-export=reports/summary.json --out json=reports/results.jsonOr use the provided script:
./scripts/run.sh -
Generate HTML Report: Navigate to the
reportsdirectory and run the report generator:cd reports
node k6-html-report-generator.js
Viewing Reports
-
After running the above steps, open the generated HTML report (e.g.,
k6-dashboard.html) in your browser to view the performance metrics and analysis. -
Reports are located in the
reports/directory.Refer How to View Reports
To see results
python3 -m http.server 9999 --directory reports/
After reviewing the reports
After reviewing the reports, exit the server by pressing "Ctrl + C" to proceed with further testing.
Customization
- Add new test files in the
tests/directory. - Use the
modules/andutils/folders to extend helpers and metrics. - Update
data/for data-driven scenarios.
Reporting
- Reports are generated in both HTML and JSON formats for easy analysis.
- Use the
k6-html-report-generator.jsscript to convert results to HTML.