Sequential Dependencies
Sequential Dependencies
Sequential dependencies ensure tests run in a specific order, where each test waits for its predecessor to complete before starting.
In sequential mode:
- Tests run in the order specified by the dependency arrows
- If a test fails, subsequent tests will not run (except for teardown tests)
- Each test must complete before the next one begins
- This ensures data consistency and proper state management between tests
Layer-based Dependencies
Layer-based Dependencies
Layer-based dependencies organize tests into layers, where all tests in one layer must complete before any tests in the next layer can begin.
In layer-based mode:
- Tests are organized into numbered layers (Layer 0, Layer 1, etc.)
- All tests within a layer can run in parallel
- A layer must complete all its tests before the next layer begins
- This enables efficient test execution while maintaining necessary dependencies
Teardown Tests
Key Features
- Run even if previous tests fail
- Used for cleaning up resources
- Maintain clean state between runs
- Ensure proper resource cleanup
Resource Cleanup
- Deleting test data
- Removing created users
- Closing connections
- Reverting system changes
Example Use Cases
- Simple Dependency Chains
For an e-commerce flow:
1
User Registration
Create a new account
2
User Login
Sign in with the new account
3
Add to Cart
Browse and add items
4
Checkout Process
Complete the purchase
Each step builds on the previous one. Keystone recognizes these relationships and ensures they execute in order, even when running tests in parallel.
Smart Data Sharing
Automatic Data Flow
When one test creates data that another needs, Keystone automatically passes it along:
Failure Handling
Skip dependent tests
Skip dependent tests
If user registration fails, login and profile tests are automatically skipped
Provide clear reasons
Provide clear reasons
Each skipped test shows exactly why it couldn’t run
Continue other flows
Continue other flows
Independent test branches continue running normally
Best Practices
Organize Dependencies Logically
- Group related tests together
- Keep dependency chains as short as possible
- Use layers for tests that can run in parallel
Use Teardown Tests Effectively
- Keep teardown tests focused on cleanup only
- Always include teardown for resource-intensive tests
Plan Your Test Structure
- Consider dependencies during test design
- Review and optimize test execution order
Monitor and Maintain
- Optimize for execution time
- Remove unnecessary dependencies
- Use conditional dependencies wisely

