Problem
Currently there is no hook that runs after test filtering — users can only hook into discovery (all tests) or execution (per test). There's no point where a user can see the final set of tests that will actually run and act on that information.
Additionally, the TestDiscoveryContext for [Before/After(TestDiscovery)] hooks could expose more capabilities — allowing users to do custom ordering and filtering of discovered tests.
Proposed Changes
1. Expand TestDiscoveryContext
Give users access to the full set of discovered tests with APIs for custom ordering and filtering:
[Before(HookType.TestDiscovery)]
public static void OnDiscovery(TestDiscoveryContext context)
{
// Access all discovered tests
var allTests = context.Tests;
// Custom ordering
context.ReorderTests(tests => tests.OrderBy(t => t.DisplayName));
// Custom filtering
context.ExcludeTests(t => t.Categories.Contains("Nightly") && !IsNightlyRun);
}
2. Add HookType.Filtering with [Before/After(Filtering)]
A new lifecycle hook that runs after the framework applies its own filtering (treenode-filter, explicit attributes, etc.) but before execution begins. The context exposes the final set of tests that will be executed in the current session:
[Before(HookType.Filtering)]
public static void BeforeFiltering(TestFilteringContext context)
{
// All tests that passed framework filtering and will be executed
var testsToRun = context.Tests;
// Could still exclude tests
context.ExcludeTests(t => ...);
// Could reorder
context.ReorderTests(tests => ...);
}
[After(HookType.Filtering)]
public static void AfterFiltering(TestFilteringContext context)
{
// Final set after any user modifications
// Good for logging/reporting what will run
}
Lifecycle Order
1. [Before(TestDiscovery)] — scan for tests
2. [After(TestDiscovery)] — all tests discovered, custom ordering/filtering available
3. Framework filtering — treenode-filter, [Explicit], [Skip], etc.
4. [Before(Filtering)] — see/modify the filtered test set
5. [After(Filtering)] — final test set locked in
6. [Before(TestSession)] — execution begins
Notes
TestDiscoveryContext expansion and HookType.Filtering are both breaking — new enum value, new context type, expanded existing context
- The
IHookExecutor interface would need 2 new methods for the new hook type (Before/After Filtering)
[BeforeEvery/AfterEvery(Filtering)] likely not needed since filtering happens once per session
- Deferred to v2
Problem
Currently there is no hook that runs after test filtering — users can only hook into discovery (all tests) or execution (per test). There's no point where a user can see the final set of tests that will actually run and act on that information.
Additionally, the
TestDiscoveryContextfor[Before/After(TestDiscovery)]hooks could expose more capabilities — allowing users to do custom ordering and filtering of discovered tests.Proposed Changes
1. Expand
TestDiscoveryContextGive users access to the full set of discovered tests with APIs for custom ordering and filtering:
2. Add
HookType.Filteringwith[Before/After(Filtering)]A new lifecycle hook that runs after the framework applies its own filtering (treenode-filter, explicit attributes, etc.) but before execution begins. The context exposes the final set of tests that will be executed in the current session:
Lifecycle Order
Notes
TestDiscoveryContextexpansion andHookType.Filteringare both breaking — new enum value, new context type, expanded existing contextIHookExecutorinterface would need 2 new methods for the new hook type (Before/After Filtering)[BeforeEvery/AfterEvery(Filtering)]likely not needed since filtering happens once per session