Generate SaaS Multi-Tenant Test Data with MockHero
The Problem
Multi-tenant SaaS applications have the most complex data models in software. Every record belongs to a tenant (organization), users have roles within tenants, resources are scoped by tenant, and permissions cross-cut everything. Testing this requires data that spans multiple organizations with overlapping user patterns, and the most critical bugs are tenant isolation failures: when one tenant can see another tenant's data.
Building this test data manually is a nightmare. You need multiple organizations, users in each org with different roles, resources owned by each org, and you need to verify that queries never leak data across tenant boundaries. Most developers test with a single tenant and hope for the best.
The Solution: MockHero Multi-Tenant Data
MockHero's ref fields naturally model multi-tenant relationships. Define organizations, then reference them from users, projects, and any other tenant-scoped entity. MockHero ensures every child record belongs to a valid parent organization, giving you the data structure needed to test tenant isolation thoroughly.
Quick Setup
curl -X POST https://api.mockhero.dev/api/v1/generate \
-H "x-api-key: mh_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"tables": [
{
"name": "organizations",
"count": 10,
"fields": [
{ "name": "id", "type": "uuid" },
{ "name": "name", "type": "company_name" },
{ "name": "slug", "type": "slug" },
{ "name": "plan", "type": "enum", "params": { "values": ["free","starter","pro","enterprise"] } },
{ "name": "created_at", "type": "datetime" }
]
},
{
"name": "users",
"count": 60,
"fields": [
{ "name": "id", "type": "uuid" },
{ "name": "org_id", "type": "ref", "params": { "ref": "organizations.id" } },
{ "name": "full_name", "type": "full_name" },
{ "name": "email", "type": "email" },
{ "name": "role", "type": "enum", "params": { "values": ["owner","admin","member","viewer","billing"] } },
{ "name": "invited_at", "type": "datetime" }
]
},
{
"name": "projects",
"count": 100,
"fields": [
{ "name": "id", "type": "uuid" },
{ "name": "org_id", "type": "ref", "params": { "ref": "organizations.id" } },
{ "name": "created_by", "type": "ref", "params": { "ref": "users.id" } },
{ "name": "name", "type": "sentence" },
{ "name": "description", "type": "paragraphs" },
{ "name": "status", "type": "enum", "params": { "values": ["active","archived","paused"] } }
]
},
{
"name": "api_keys",
"count": 30,
"fields": [
{ "name": "id", "type": "uuid" },
{ "name": "org_id", "type": "ref", "params": { "ref": "organizations.id" } },
{ "name": "name", "type": "sentence" },
{ "name": "prefix", "type": "uuid" },
{ "name": "last_used_at", "type": "datetime" },
{ "name": "revoked", "type": "boolean" }
]
}
],
"format": "json"
}'
Step-by-Step Guide
1. Model your tenant hierarchy
Start with your organization table, then add every entity that is tenant-scoped. Use ref fields pointing to organizations.id for every table that belongs to a tenant. This mirrors how you would design RLS (Row Level Security) policies in production.
2. Get your MockHero API key
Sign up at mockhero.dev/sign-up and copy your API key.
3. Generate the multi-tenant dataset
const res = await fetch("https://api.mockhero.dev/api/v1/generate", {
method: "POST",
headers: {
"x-api-key": process.env.MOCKHERO_API_KEY,
"Content-Type": "application/json",
},
body: JSON.stringify({
tables: [
// organizations, users, projects, api_keys schema from above
],
format: "json",
}),
});
const { data } = await res.json();
// data.organizations - 10 tenants
// data.users - 60 users spread across tenants
// data.projects - 100 projects scoped to tenants
// data.api_keys - 30 keys scoped to tenants
4. Test tenant isolation
With data spread across 10 organizations, you can write tests that authenticate as a user in org A and verify they cannot access projects belonging to org B. This is the most critical security test for any SaaS application.
5. Test role-based access
MockHero's enum fields distribute users across all five roles (owner, admin, member, viewer, billing). Test that each role can only perform its permitted actions within the correct tenant.
Why MockHero vs Manual Multi-Tenant Seeds
- Multi-level relationships — organizations own users, projects, and API keys. All foreign keys are valid out of the box.
- Isolation testing — 10 tenants with distributed data makes it easy to verify that RLS policies and authorization checks work correctly.
- Role distribution — enum fields ensure all role types are represented, so you test every permission path.
- Scalable — increase counts to test with 100 tenants and 10,000 users for load testing multi-tenant systems.
Get Started
Test your SaaS app with realistic multi-tenant data. Sign up free at mockhero.dev and get 1,000 rows per month.
MockHero Team
Guides and tutorials for generating realistic test data with the MockHero API.
Start generating test data for free
1,000 rows/month on the free tier. No credit card required.
Get Your API Key