Mock Data Generation: Create Realistic Test Datasets
Testing with realistic data is crucial. Mock data generators create fake but believable data for development, testing, and demos.
Why Use Mock Data?
- Testing: Validate application behavior with various inputs
- Development: Build UIs before backend is ready
- Demos: Show features with realistic-looking data
- Privacy: Avoid using real customer data in non-production
- Performance: Load test with large datasets
Types of Mock Data
User Data
{
"id": "uuid-1234",
"name": "John Doe",
"email": "john.doe@example.com",
"age": 32,
"address": {
"street": "123 Main St",
"city": "San Francisco",
"state": "CA",
"zip": "94102"
},
"joinedAt": "2024-01-15T10:30:00Z"
}E-commerce Data
{
"productId": "prod-5678",
"name": "Wireless Headphones",
"price": 79.99,
"category": "Electronics",
"inStock": true,
"rating": 4.5,
"reviews": 128
}JavaScript Mock Data Generation
Using Faker.js
import { faker } from '@faker-js/faker';
// Generate user
const user = {
id: faker.string.uuid(),
name: faker.person.fullName(),
email: faker.internet.email(),
avatar: faker.image.avatar(),
birthdate: faker.date.birthdate(),
company: faker.company.name()
};
// Generate array of users
const users = faker.helpers.multiple(() => ({
name: faker.person.fullName(),
email: faker.internet.email()
}), { count: 100 });Custom Generators
function generateUser() {
const firstNames = ['John', 'Jane', 'Bob', 'Alice'];
const lastNames = ['Smith', 'Doe', 'Johnson', 'Williams'];
const firstName = firstNames[Math.floor(Math.random() * firstNames.length)];
const lastName = lastNames[Math.floor(Math.random() * lastNames.length)];
return {
id: Math.random().toString(36).substr(2, 9),
name: `${firstName} ${lastName}`,
email: `${firstName.toLowerCase()}.${lastName.toLowerCase()}@example.com`,
age: Math.floor(Math.random() * 50) + 20
};
}🎲 Generate Mock Data Instantly
Use our free Mock Data Generator to create realistic test datasets for users, products, transactions, and more. AI-powered generation with custom schemas.
Generate Mock Data →API Mocking
JSON Server
// db.json
{
"users": [
{"id": 1, "name": "John Doe", "email": "john@example.com"},
{"id": 2, "name": "Jane Smith", "email": "jane@example.com"}
],
"posts": [
{"id": 1, "title": "Hello World", "userId": 1}
]
}
// Start server
json-server --watch db.json --port 3000
// API endpoints created automatically:
// GET /users
// GET /users/1
// POST /users
// PUT /users/1
// DELETE /users/1Best Practices
- ✅ Use consistent data formats (email, phone, dates)
- ✅ Generate data that matches production patterns
- ✅ Include edge cases (empty strings, nulls, special chars)
- ✅ Use seeds for reproducible data
- ❌ Don't use real customer data in development
- ❌ Don't hardcode mock data in source code