Constraints
Constraints define the rules and requirements for generating test data. While schemas define the structure, constraints control the actual values and relationships in your test data.
Where you'll work with constraints
- Project page: Create constraints for specific schemas
- Library: Browse all available constraint sets
- Constraints editor: The interface for defining constraint sets
Understanding constraints
Constraints are rules defined on top of the schema, i.e., they enhance the schema by offering more control over the generated data. With constraints, you can specify:
- Any constraints that are specifiable with a schema
- One-time constraints for targeted test data
- Conditional requirements (e.g., if field A is X, then field B must be Y)
- Relationships between fields (e.g., start date before end date)
- Formatting rules and patterns (e.g., German phone number format)
Example: For a user schema, you might define constraints like:
- Email must be a valid format
- Age must be between 18 and 120
- If country is "Germany", a valid German ZIP code must be provided
- Registration date must be within the last 90 days
Working with constraint sets
A constraint set is a saved collection of constraints that can be reused across multiple dataset generations.
Benefits of constraint sets:
- Save time by reusing common configurations
- Ensure consistency across test runs
- Share proven configurations with team members
- Maintain different sets for different scenarios (happy path, edge cases, load testing)
Typical workflow
- Select a schema: Choose the data structure you're working with
- Create a constraint set: Define rules for what data should be generated
- Configure constraints: Set specific rules for each field
- Save the constraint set: Give it a clear name for reuse
- Generate datasets: Use the constraint set to produce test data
Types of constraints you can define
Required fields
Mark which fields must have values in every generated record.
Value ranges
Set minimum and maximum values for numeric and date fields.
- Example: Age between 21 and 65
- Example: Order date within the last 30 days
Enumerations
Specify exact list of allowed values.
- Example: Status can only be "active", "pending", or "inactive"
- Example: Country code from ISO country list
Format patterns
Define patterns for string fields.
- Example: Phone numbers in format (XXX) XXX-XXXX
- Example: Product codes matching pattern ABC-1234
Field relationships
Create rules between related fields.
- Example: End date must be after start date
- Example: Discount percentage must be less than price
Uniqueness
Ensure certain fields generate unique values across all records.
- Example: User IDs must be unique
- Example: Email addresses must be unique
Creating effective constraint sets
Start simple: Begin with basic constraints and add complexity as needed.
Test with small datasets: Generate 10-20 records first to verify your constraints work as expected.
Use descriptive names: Name constraint sets clearly to indicate their purpose.
Document your intent: Add descriptions explaining what scenarios the constraint set is designed for.
Organize by scenario: Create different constraint sets for different testing needs:
- Happy path testing
- Edge case testing
- Performance/load testing
- Negative testing
Tips for managing constraints
- Review regularly: Update constraints when application requirements change
- Version control: Create new constraint sets rather than modifying critical ones
- Share with team: Make useful constraint sets available to others
- Avoid conflicts: Ensure constraints don't contradict each other (e.g., min > max)
- Consider performance: Complex constraints may take longer to generate
Next steps
After creating constraint sets:
- Test generation: Create a small dataset to verify constraints work correctly
- Refine as needed: Adjust constraints based on generated results
- Generate production datasets: Create full-size datasets for testing