Skip to main content

K6 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:

npm install

Install simple-statistics for HTML report generation:

npm install simple-statistics

Running Tests

  1. Run the k6 Test:

     k6 run tests/user.test.js --summary-export=reports/summary.json --out json=reports/results.json

    Or use the provided script:

    ./scripts/run.sh
  2. Generate HTML Report: Navigate to the reports directory 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.
  python3 -m http.server 9999 --d .

Customization

  • Add new test files in the tests/ directory.
  • Use the modules/ and utils/ 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.js script to convert results to HTML.

Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you would like to change.

License

This project is licensed under the MIT License.