UUID Use Case

UUID Test Data

Tests need believable, unique IDs. A batch of v4 UUIDs gives you exactly that without a database sequence.

RealisticNon-collidingv4

Generated locally with the Web Crypto API — nothing leaves your browser.

What Is UUID Test Data?

How to generate

  1. Generate a batch with crypto.randomUUID() in a factory.
  2. Use them as primary and foreign keys in fixtures.
  3. Never hardcode a specific UUID unless a test needs it.

Use Cases

Code Examples

JavaScript
const makeUser = () => ({ id: crypto.randomUUID(), name: 'Test' });
Python
import uuid
user = {'id': str(uuid.uuid4()), 'name': 'Test'}

Frequently Asked Questions

Hardcode a UUID in a test?
Only when the test asserts on that exact value; otherwise generate fresh to avoid cross-test coupling.
UUIDs slow down tests?
No — generation is microseconds; the realism benefit outweighs it.

Related tools