
User-friendly user test data generation?
test data | npm packages | TypeScript | Playwright |
you no longer need to create it yourself
Worked in multiple companies, I’ve seen various test data generation approaches, but what if I have told you that you dont need to create those functions yourself?
I’ve recently discovered an interesting node package that works great for your test data creation, with over 50 millions combinations out of the box, virtually eliminating collisions
“Was that the test with user 3891981 or 4792847?”
And you no longer need to floor your applications with users named like this: [email protected] which could be harder to debug with.. or/and difficult to discuss with team members
Instead of this:
const testUser = `AutomationUser${Math.floor(Math.random() * 1000000)}@gmail.com`
// Result: [email protected]
You get this:
import { uniqueNamesGenerator, adjectives, colors, animals } from 'unique-names-generator';
const testUser = `${uniqueNamesGenerator({
dictionaries: [adjectives, colors, animals]
})}@example.com`;
// Result: [email protected]
Which scenario is easier to debug?
- “The test failed for user 847392”
- “The test failed for the brave crimson elephant”
Tip: when generating test emails, avoid using real domains like @gmail.com if your application actually sends emails during testing. This can save your company money on email delivery services, especially if you don't need to actually log into those user accounts - just verify that invitations or notifications are triggered.
Birthday Paradox
You should always have proper teardown for your tests to avoid data flooding, but let’s be honest — sometimes it just isn’t available, especially when you can’t teardown via UI, direct database manipulation, or API calls. When leftover test data accumulates, you’ll hit the birthday paradox faster than expected. With just 119 random numbers between 1–10,000, you have a 50% chance of collision. Scale that across parallel test runs and previous test remnants, and you’re asking for trouble. Your CI runs 200 tests, encounters an existing TestUser8472 from yesterday's incomplete cleanup, and boom - a perfectly good test fails mysteriously. These aren't edge cases, they're mathematical certainties waiting to bite you.
Customizable and tree-shakeable
What makes this package special is that it’s really flexible and easy to use. You don’t have to use everything at once. You can choose just the parts you need. For example, you can mix and match different lists like adjectives, colors, animals, countries, names, or even Star Wars characters. You get to pick the separators and how the names look (like uppercase, lowercase, etc.). You can even make your own lists for your business or project.
Here are some examples:
To make product names, you could use: [adjectives, colors, [Laptop,'Phone', 'Tablet']]Or, for a game, you might want:[starWars, colors]to create fun character names.
The package also makes sure you only use what you need, which makes it lightweight and efficient in the modern testing stack!