Mock Data Generation: Strategies, Tools, and Best Practices for Testing
Learn how to generate realistic fake data for development and testing: names, emails, dates, UUIDs, addresses, and structured records — without using real user data.
Try the free online tool mentioned in this guide:Mock Data Generator
Why use mock data instead of real data
Using production data in development and testing environments creates serious privacy, legal, and security risks. Real user data exposed in a dev environment violates GDPR, CCPA, and most privacy policies. A single misconfigured environment variable can leak it publicly.
Mock (fake) data that is structurally identical to real data solves this: developers can work with realistic records, seed databases, test UI edge cases, and run integration tests without ever touching a real user's information.
What to generate: common data types
Identity: first name, last name, username, email address, phone number, avatar URL.
Location: street address, city, state, country, postal code, latitude/longitude.
Finance: credit card number (test ranges only), IBAN, currency amount, company name.
Internet: URL, domain, IP address, user agent string, password.
Dates and times: birthdate, created_at, event timestamp, ISO 8601 strings.
Identifiers: UUID v4, ULID, sequential ID, SKU, order number.
Content: lorem ipsum paragraphs, sentences, words — useful for seeding blog posts, comments, or descriptions.
Mock data in code: Faker.js
Faker.js (@faker-js/faker) is the most popular JavaScript/TypeScript library for generating mock data. It supports 50+ locales for realistic locale-specific data.
import { faker } from "@faker-js/faker"
// Generate a single user record
const user = {
id: faker.string.uuid(),
firstName: faker.person.firstName(),
lastName: faker.person.lastName(),
email: faker.internet.email(),
phone: faker.phone.number(),
avatar: faker.image.avatar(),
address: {
street: faker.location.streetAddress(),
city: faker.location.city(),
country: faker.location.country(),
zip: faker.location.zipCode(),
},
createdAt: faker.date.past({ years: 2 }).toISOString(),
}
// Generate 100 users
const users = Array.from({ length: 100 }, () => ({
id: faker.string.uuid(),
name: faker.person.fullName(),
email: faker.internet.email(),
}))Seeding: reproducible mock data
By default, Faker generates random data on each run — so test assertions that depend on specific values will fail. Use a seed to make generation deterministic: the same seed always produces the same sequence of values.
import { faker } from "@faker-js/faker"
// Seeded — same output every run
faker.seed(12345)
console.log(faker.person.firstName()) // always the same name
// Reset seed for a fresh sequence
faker.seed()Database seeding patterns
Development seeding: populate a local database with realistic records to develop against. Run a seed script on npm run dev:setup or before tests.
Factory pattern: define a factory function per model. Compose factories for related records (a user factory that creates associated orders).
Fixtures: static JSON or SQL files with known data. Used for specific test scenarios where exact values matter (e.g., testing boundary conditions).
Online generators: useful for one-off needs — generate 50 user records as JSON, paste into Postman or a database client. MyDevTools Mock Data Generator produces JSON, CSV, or SQL INSERT statements ready to use.
// Factory pattern example
function createUser(overrides = {}) {
return {
id: faker.string.uuid(),
email: faker.internet.email(),
role: "user",
active: true,
...overrides, // caller can override any field
}
}
// Specific test scenarios
const adminUser = createUser({ role: "admin" })
const inactiveUser = createUser({ active: false })
const bulkUsers = Array.from({ length: 50 }, () => createUser())Frequently asked questions
What is the difference between mock data and test fixtures?
Mock data is randomly generated to simulate realistic inputs — good for volume testing and UI development. Fixtures are static, known data sets used when exact values matter for specific test assertions.
Is it safe to use fake credit card numbers for testing?
Faker generates structurally valid-looking numbers that pass Luhn checksum but are not real card numbers. Use them only in internal dev/test environments. Payment providers like Stripe have official test card numbers — use those for payment integration testing.
How do I generate mock data that matches my database schema?
Define a factory function per model that generates all required fields with the right types. MyDevTools Mock Data Generator lets you define field names, types, and counts to match a specific schema structure.
Can I generate mock data in CSV or SQL format?
Yes. MyDevTools Mock Data Generator outputs JSON, CSV (ready for spreadsheet or database import), and SQL INSERT statements for directly seeding a database table.

