Implement filter functionality #42
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Test Filtering Feature
This document describes the test filtering functionality in Testo, which allows selective test execution based on various criteria.
Overview
Testo provides a flexible filtering system that operates in multiple stages:
This multi-stage approach optimizes performance by progressively narrowing down the test set, skipping unnecessary operations at each level.
Filter Types
The filtering system supports three types of filters, each working independently:
1. Name Filter (
--filter)Filters tests by method or function names. Supports three formats:
Namespace\ClassNameorNamespace\functionNameClassName::methodNameorNamespace\ClassName::methodNamemethodName,functionName, orShortClassName2. Path Filter (
--path)Filters test files by glob patterns with wildcard support (
*,?,[abc]).3. Suite Filter (
--suite)Filters tests by test suite name.
Filter Logic
Combining Multiple Filters
Same type filters use OR logic: Multiple values of the same filter type are combined with OR
--filter=test1 --filter=test2matches tests where name istest1ORtest2Different type filters use AND logic: Different filter types are combined with AND
--filter=test1 --path="tests/Unit/*"matches tests where name istest1AND file is intests/Unit/Formula:
AND(OR(filters), OR(paths), OR(suites))Name Filter Behavior
When filtering by name (
--filter), the behavior depends on the filter format:Method Format (
ClassName::methodName)When using the method format with
::separator:--filter=UserTest::testLoginincludes onlytestLoginmethod fromUserTestclassFQN or Fragment Format
When using FQN (with
\) or simple fragment (no separators):Class name match: If the test case class name matches the filter
Class name doesn't match: If the test case class name doesn't match
Examples:
--filter=UserTest→ includes entireUserTestclass with all methods--filter=Tests\Unit\UserTest→ includes entire class with all methods--filter=testLogin→ includes any class that hastestLoginmethod, with only that methodUsage Examples
Basic Filtering
Filter by Test Name
Filter by Suite
# Filter by test suite name (OR logic) ./bin/testo run --suite=Unit --suite=IntegrationComplex Filtering
CI Integration
Implementation Details
Multi-Stage Filtering Pipeline
Stage 1: Suite Filter (Configuration Level)
Applied at the configuration level to determine which test suites to run:
--suiteoptionStage 2: Path Filter (Finder Level)
Applied at the file finder level during directory scanning:
--pathoption with glob patterns*,?,[abc])Stage 3: File Filter (FilterInterceptor - FileLocatorInterceptor)
Implemented in
FilterInterceptor::locateFile():--filterpatterns before loading reflectionsStage 4: Test Filter (FilterInterceptor - CaseLocatorInterceptor)
Implemented in
FilterInterceptor::locateTestCases():::) - filters specific methods onlyPattern Matching
The filter uses whole-word matching with regex:
This ensures:
UsermatchesApp\Userbut notApp\UserManagertestmatchestestMethodbut notlatestMethodPerformance Considerations
Command Reference
Arguments
path(optional): Path to test directory or fileOptions
--filter: Filter methods or functions to be run (repeatable)methodName,ClassName::methodName, andNamespace\ClassName::methodNameformats--path: Glob patterns for test files to be run (repeatable)*,?,[abc]--suite: Filter test suites by name (repeatable)--teamcity: Enable TeamCity CI output format--config: Path to the configuration fileExamples by Use Case
Run specific test method
Run all tests in a class
Run tests across multiple files
Run critical tests in specific directory
./bin/testo run --path="tests/Unit/*" --suite=CriticalRun specific methods from multiple classes
CI/CD Pipeline