Giter VIP home page Giter VIP logo

farhanlabib / k6-faker-load-testing Goto Github PK

View Code? Open in Web Editor NEW
14.0 1.0 0.0 1.54 MB

k6-faker is a small example project that demonstrates how to use the Faker.js library with the k6 load testing tool. It generates random user data objects and uses k6 to send HTTP requests to an API endpoint with the generated data. The project includes a test script and instructions for getting started.

JavaScript 100.00%
faker-js javascript k6

k6-faker-load-testing's Introduction

k6-faker-load-testing

k6JavaScript

k6-faker-load-testing

k6-faker is a small project that demonstrates how to use the Faker library with k6, a modern load testing tool.

This project includes a simple k6 script that creates a fake user using Faker and posts it to the FakeStoreAPI for testing purposes.

Getting Started

To use this framework, you need to have Node.js and k6 installed on your machine.

  • Clone the Repository
> git clone https://github.com/farhanlabib/k6-faker-load-testing.git
> cd k6-faker-load-testing
> npm install
  • Install k6
https://k6.io/docs/get-started/installation/

Folder Structure

Code is structured as shown below:

k6-Performance-Testing-Framework/
 ├── specs                                # The k6 test file is located in the spec folder.
 │    ├──main.js                          # Main k6 Script
 │    ├──test.js                          # Console Log File
 │
 ├── payload.js                           # Function for generate fake user data   

Configuring the Test

The performance tests are configured using the options variable in the test script. The options variable defines the stages of the load test, including the duration and target number of requests per second for each stage.

The current configuration is set up as follows:

  • Stage 1: 5 second duration and target of 1 requests per second

Writing the Test

The main.js file contains the main function that will be executed for each virtual user. This function generates random user data using the userData function from the payload.js file, sends a POST request to the API with the generated data, and checks the response status code and response time using the k6 check function.

The payload.js file contains a function userData that generates a random user data object using the Faker.js library. The user data object contains properties such as email, username, password, name, address, and phone, with each property having randomly generated values using the Faker.js library.

Run the Test

k6 run specs/main.js

This command will execute the test file and provide a summary of the test results in the console.

k6 run --log-format raw specs/main.js --console-output=./test.csv 

This command will execute the test file and provide a detailed raw log of the test results in a csv file.

Conclusion

This is a basic example of how to use the the Faker.js library with the k6 load testing tool. You can customize the test to suit your needs by changing the options and the test function.

Feel free to fork and make pull request for any additional feature.

k6-faker-load-testing's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

k6-faker-load-testing's Issues

Source Map Support Disabled

I encountered an error when attempting to import and execute the load test.

Screenshot 2024-02-08 at 1 23 00 PM

The source for `https://cdnjs.cloudfare.com/ajax/libs/Faker/3.1.0/faker.min.js` needs to go through babel but is over 256000 bytes. For performance reasons source map support will be disabled for this particular file.

ERRO[0001] SyntaxError: https://cdnjs.cloudfare.com/ajax/libs/Faker/3.1.0/faker.min.js: Unexpected token (1:0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.