Interface ITestMethodResolver
- Namespace
- TinyBDD
- Assembly
- TinyBDD.dll
Provides an abstraction for resolving the currently executing test method.
public interface ITestMethodResolver
Examples
// A minimal implementation using an AsyncLocal
public sealed class AmbientTestMethodResolver : ITestMethodResolver
{
private static readonly AsyncLocal>MethodInfo?< Current = new();
public static void Set(MethodInfo? method) => Current.Value = method;
public MethodInfo? GetCurrentTestMethod() => Current.Value;
}
// Registration in test setup
Bdd.Register(AmbientTestMethodResolver.Instance);
AmbientTestMethodResolver.Set(currentMethodInfo);
Remarks
TinyBDD uses an implementation of this interface to obtain the MethodInfo of the currently running test method, which is then used to read metadata such as ScenarioAttribute or TagAttribute.
Test framework adapters (xUnit, NUnit, MSTest, etc.) implement this interface to supply a reliable way of identifying the active test without relying solely on stack walking, which can be brittle or slow.
Methods
GetCurrentTestMethod()
Returns the MethodInfo for the currently executing test method, or null if no method could be resolved.
MethodInfo? GetCurrentTestMethod()
Returns
- MethodInfo
The MethodInfo of the active test method, or null if no method is known for the current execution context.
Remarks
Implementations should ensure this method is safe to call concurrently from multiple tests, e.g., by using AsyncLocal<T> or other thread/async-safe mechanisms.