Interface IStepObserver
- Namespace
- TinyBDD
- Assembly
- TinyBDD.dll
Observes step-level lifecycle events during scenario execution.
public interface IStepObserver
Examples
public class StepTimingObserver : IStepObserver
{
public ValueTask OnStepStarting(ScenarioContext context, StepInfo step)
{
Console.WriteLine($"Starting: {step.Kind} {step.Title}");
return default;
}
public ValueTask OnStepFinished(ScenarioContext context, StepInfo step, StepResult result, StepIO io)
{
Console.WriteLine($"Finished: {step.Kind} {step.Title} in {result.Elapsed.TotalMilliseconds}ms");
return default;
}
}
Remarks
Implementations can use this interface to add cross-cutting concerns like structured logging, distributed tracing, or diagnostics at the individual step level. Observers are registered via AddObserver(IStepObserver).
Methods
OnStepFinished(ScenarioContext, StepInfo, StepResult, StepIO)
Called after a step completes execution, regardless of success or failure.
ValueTask OnStepFinished(ScenarioContext context, StepInfo step, StepResult result, StepIO io)
Parameters
contextScenarioContextThe scenario context with all executed steps.
stepStepInfoMetadata about the step that executed.
resultStepResultThe execution result including timing and error information.
ioStepIOThe input/output values captured during step execution.
Returns
- ValueTask
A ValueTask representing the asynchronous operation.
OnStepStarting(ScenarioContext, StepInfo)
Called immediately before a step begins executing.
ValueTask OnStepStarting(ScenarioContext context, StepInfo step)
Parameters
contextScenarioContextThe scenario context containing feature, scenario, and tag metadata.
stepStepInfoMetadata about the step that is about to execute.
Returns
- ValueTask
A ValueTask representing the asynchronous operation.