Fake Data Documentation #79
Dynavy
started this conversation in
Show and tell
Replies: 1 comment
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Overview
Fake data is used for testing, development, and debugging purposes. It simulates real data without compromising privacy or security, ensuring that applications can be tested and developed efficiently.
In our application, Java Faker is used to generate fake data for entities like users, groups, and plans, which are then inserted into the database.
Maven repository dependecy --> https://mvnrepository.com/artifact/net.datafaker/datafaker/2.4.2
Purpose of Fake Data
Testing: Fake data helps test functionality without relying on real data.
Simulating Production: It mimics real-world data for performance and scalability testing.
Faster Development: Enables quick testing of features without needing real data.
Database Population: Useful for filling empty databases with mock data for testing.
Implementation
Fake Data Generation
FakeDataService: A service that uses Java Faker to generate and insert fake data into the database.
FakeDataController Endpoints:
POST /api/fake-data/users
: Generates a specified number of fake users. Use?count=<number>
to specify the number of users to create.?count=<number>
to specify how many users to generate.POST /api/fake-data/groups
: Generates groups with random users as members.?count=<number>
to specify how many groups to generate.POST /api/fake-data/plans
: Generates fake plans with random details. Use?count=<number>
to define the number of plans to create.?count=<number>
to specify how many plans to generate.These endpoints are for creating fake data to the database during testing or development.
Data Deletion Endpoints
In addition to generating fake data, there are endpoints that allow for clearing the data from each table:
POST /api/fake-data/clear-users
: Deletes users data from the database.POST /api/fake-data/clear-groups
: Deletes groups data from the database.POST /api/fake-data/clear-plans
: Deletes plans data from the database.These endpoints are for managing and restoring fake data to the database during testing or development.
Process
Generate Users: Fake names, emails, and phone numbers are generated using
Java Faker
.Generate Groups: Groups are created with random users assigned to them.
Generate Plans: Randomly generated plans with titles, descriptions, and deadlines are inserted into the database.
Repositories: Data is saved using the appropriate repositories (
UserRepository
,GroupRepository
, etc.).Integration with Flyway Migrations
Flyway and Fake Data
Flyway handles database migrations, creating the necessary tables and columns.
Fake Data does not affect Flyway migrations as it only inserts data into existing tables.
Workflow
Flyway Migrations First: Run Flyway migrations to create the database schema.
Generate Fake Data: After migrations, use the endpoints to populate the database with fake data.
No Schema Changes: Fake data generation only inserts data, leaving the schema intact.
Key Points
Flyway handles schema changes (tables, columns, etc.).
Fake Data is inserted into already existing tables and does not alter the schema.
Fake data generation works independently of Flyway migrations, ensuring that migrations are never impacted.
Conclusion
Flyway Migrations ensure the correct schema setup.
Fake Data generation allows for testing and development with mock data, providing flexibility without interfering with the schema.
This combination ensures efficient development and testing without compromising database integrity.
Beta Was this translation helpful? Give feedback.
All reactions