Skip to content

Implement Mock Data provider for API Testing #496

@varshil-shah

Description

@varshil-shah

Implement Mock Data provider for API Testing

Description

Currently, when testing API endpoints in the API Dash repository, users must manually enter or modify details such as email, username, and other user-specific information. This manual effort can be tedious and error-prone, especially during repeated testing. To streamline this process, we propose implementing a feature that generates random placeholder values for common fields like email, username, etc.

Feature Details

Introduce a set of predefined random data variables (e.g., {{$randomEmail}}, {{$randomUsername}}) that can be used in the API requests. These placeholders will automatically populate with randomized data when the API is called, allowing testers to quickly simulate unique user details without manual input.

Benefits

  • Increased Efficiency: Simplifies testing by automating data entry, reducing repetitive manual work.
  • Consistency: Standardizes testing by providing consistent random values across sessions.
  • Enhanced User Experience: Enables faster and more reliable API testing workflows.

Implementation Suggestions

  1. Define random generators for various data types (e.g., email, username, numeric ID).
  2. Update the API to recognize and replace variables like {{$randomEmail}} with generated values.
  3. Ensure variables can be used across multiple endpoints, maintaining flexibility and ease of use.

This feature will greatly enhance developer productivity and provide a more seamless testing experience in the API Dash environment.

Activity

varshil-shah

varshil-shah commented on Nov 9, 2024

@varshil-shah
Author

Can I work on this issue???

ashitaprasad

ashitaprasad commented on Nov 9, 2024

@ashitaprasad
Member

You can mention the below details in this thread:

  1. Where are you planning to add this feature in the UI? How will the user know this feature is available ?
  2. List of random data you will provide - how will you provide it? what package will you use?
  3. We already have environment variables .. will you leverage it?
changed the title [-]Implement Random Data Generator for API Dash Repository[/-] [+]Implement Mock Data Generator for API Testing[/+] on Nov 9, 2024
changed the title [-]Implement Mock Data Generator for API Testing[/-] [+]Implement Mock Data provider for API Testing[/+] on Nov 9, 2024
varshil-shah

varshil-shah commented on Nov 9, 2024

@varshil-shah
Author

Implementation Details

  • UI Addition:
    This feature will be accessible within the request body editor. Users can invoke it by typing {{ (double curly brackets), which will reveal the list of available random placeholders.

  • Random Data Types:
    Initial options will include random values for email, username, names, and potentially others. The faker package in Flutter will be used to generate this data without needing to modify environment variables.

  • Package Used:
    I will utilize the faker package for Flutter to generate these random values.

  • Environment Variables:
    No need to leverage environment variables for this feature, as the faker package provides sufficient randomness for testing purposes.

ashitaprasad

ashitaprasad commented on Nov 9, 2024

@ashitaprasad
Member

As you are a first time contributor to this project, I recommend you to pick up an open issue first and resolve it to get familiar with the codebase, before working on adding this completely new feature.

varshil-shah

varshil-shah commented on Nov 9, 2024

@varshil-shah
Author

Alright, Thanks for your response.

abhinavs1920

abhinavs1920 commented on Apr 4, 2025

@abhinavs1920
Contributor

First, I’ll identify where user inputs (like email or username) are injected into requests. Then, I’ll create small utility functions to generate random values for common fields (e.g., randomEmail() could combine random strings with @test.com).

Next, I’ll update the request-handling logic to detect placeholders like {{$randomEmail}} in API payloads. Using regex or string replacement, I’ll swap these placeholders with the outputs of the corresponding utility functions just before sending the request.

I’ll ensure this replacement works for all endpoints, nested JSON structures, and repeated fields. To keep it lightweight, I’ll avoid external libraries and stick to simple, APIDash core functionalities,

@ashitaprasad @animator @DenserMeerkat

Please provide me feedback for my approach!

animator

animator commented on Apr 4, 2025

@animator
Member

@abhinavs1920 think how you can leverage some concept similar to env variables for this feature.

abhinavs1920

abhinavs1920 commented on Apr 5, 2025

@abhinavs1920
Contributor

@abhinavs1920 think how you can leverage some concept similar to env variables for this feature.

I'll use APIDash's current environment variables feature that is very well implemented. I'll add a new section called 'Random Generators' where testers can use special tags like {{$randomEmail}} in their API requests (Or we can use some flag to identify if they are the dummy value placeholders or not). When someone runs the request, the system will automatically replace these tags with fresh random values.

First, I'll update the code to check for these {{$...}} tags after handling normal environment variables. Simple functions will generate the random data. The UI will show examples so testers understand how to use {{$randomUsername}} or {{$randomId}} without confusion(extension of feature). This way I can use the existing implementation.

animator

animator commented on Apr 5, 2025

@animator
Member

@abhinavs1920 think how you can leverage some concept similar to env variables for this feature.

I'll use APIDash's current environment variables feature that is very well implemented. I'll add a new section called 'Random Generators' where testers can use special tags like {{$randomEmail}} in their API requests (Or we can use some flag to identify if they are the dummy value placeholders or not). When someone runs the request, the system will automatically replace these tags with fresh random values.

First, I'll update the code to check for these {{$...}} tags after handling normal environment variables. Simple functions will generate the random data. The UI will show examples so testers understand how to use {{$randomUsername}} or {{$randomId}} without confusion(extension of feature). This way I can use the existing implementation.

Random Generators => Fake Data Providers

very nice idea.

abhinavs1920

abhinavs1920 commented on Apr 5, 2025

@abhinavs1920
Contributor

@animator
Thanks! Shall I move forward with the implementation I mentioned?

Keeping in mind Fake Data Providers

animator

animator commented on Apr 5, 2025

@animator
Member

@abhinavs1920 Yes you can proceed 👍

abhinavs1920

abhinavs1920 commented on Apr 6, 2025

@abhinavs1920
Contributor

@animator
I have implemented the Fake Data Providers Pane this way, let me know the changes required.

Image

linked a pull request that will close this issue on Apr 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Participants

      @animator@ashitaprasad@varshil-shah@abhinavs1920

      Issue actions

        Implement Mock Data provider for API Testing · Issue #496 · foss42/apidash