Test dependencies in Keystone allow you to define relationships between tests and control their execution order. This page explains the different dependency modes and provides detailed examples of how they work.

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

Teardown tests are special tests marked to run at the end of a test suite, regardless of whether previous tests succeeded or failed.

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

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:
This happens seamlessly - no manual configuration required. The AI understands what data flows between tests and manages it intelligently.

Failure Handling

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