Overview
Selective testing can reduce test execution time by 60-90% by only running tests affected by your changes.
- Tests in modified targets
- Tests that depend on changed source files
- Tests affected by dependency changes
How It Works
- Track changes - Tuist compares your current code against a baseline (usually
mainbranch) - Build dependency graph - Maps which tests depend on which source files
- Calculate impact - Determines which tests could be affected by changes
- Run focused tests - Executes only the necessary test subset
Getting Started
Basic Usage
Selective testing is enabled by default when usingtuist test:
First-Time Setup
Configuration
Disable Selective Testing
Run all tests regardless of changes:Filter by Test Type
Specify Test Targets
Run specific tests even with selective testing:How Tests Are Selected
Scenarios
Modified source file
Modified source file
Change: Edit
UserService.swiftSelected tests:- All tests in targets that depend on the module containing
UserService.swift - Tests that directly import or use
UserService
Modified test file
Modified test file
Change: Edit
UserServiceTests.swiftSelected tests:- Only tests within
UserServiceTests.swift
Dependency change
Dependency change
Change: Update Alamofire from 5.8.0 to 5.9.0Selected tests:
- All tests in targets that depend on Alamofire
- All tests in targets that transitively depend on Alamofire
No changes
No changes
Change: No modified filesSelected tests:
- None (Tuist reports “No tests to run”)
- You can still force run with
--no-selective-testing
CI/CD Integration
Pull Request Testing
Selective testing shines in CI environments:GitHub Actions
Main Branch Testing
Always run full test suite on main:Caching Integration
Selective testing works seamlessly with binary caching:- Use cached binaries for unchanged dependencies
- Run only tests affected by your changes
- Upload test results to Tuist Cloud
Combining selective testing with binary caching can reduce test time by 80-95% in CI.
Understanding Test Results
Test Summary
After running tests, Tuist shows:Cloud Dashboard
View detailed test analytics in Tuist Cloud:- Test execution time trends
- Selective testing impact
- Flaky test detection
- Test success rates
Best Practices
Modular Architecture
Break your app into focused modules. Smaller, well-defined dependencies lead to better test selection.
Stable Dependencies
Keep stable code in separate frameworks. Infrequently changing dependencies won’t trigger unnecessary tests.
Comprehensive Tests
Write tests that cover public interfaces. Tuist selects tests based on dependency relationships.
Fast Test Execution
Optimize individual test speed. Selective testing reduces quantity, but each test should still be fast.
Troubleshooting
Too many tests selected
Too many tests selected
Possible causes:
- Changes in a low-level dependency affect many targets
- Wide dependency graph (everything depends on core framework)
- Project structure needs modularization
- Break up large, widely-used frameworks
- Use protocols to decouple dependencies
- Consider vertical slicing of features
No tests selected
No tests selected
Possible causes:
- No source changes detected
- Changes are in non-code files (e.g., README)
- Git comparison issues
- Verify changes with
git status - Use
--no-selective-testingto force run - Check baseline branch configuration
Tests not uploaded to cloud
Tests not uploaded to cloud
Possible causes:
- Not authenticated with Tuist Cloud
- Network connectivity issues
- Project not linked
- Run
tuist authto authenticate - Check network connectivity
- Verify project link with
tuist project show
Performance Impact
Small Changes
90-95% reductionSingle file modifications
Medium Changes
60-80% reductionMultiple related changes
Large Changes
20-40% reductionCore dependency updates
Next Steps
Build Insights
Analyze test performance and coverage
Binary Caching
Speed up test builds with caching