Skip to main content

Utilities and model

For built-in adapters, pass the configured assembly run to report/utility helpers. Every export and store utility requires the owning run. Export all reports before disposing through the assembly owner.

BDTestUtil​

BDTest.BDTestUtil is the public read API over the scenarios collected in the supplied run.

MemberReturns
GetScenarios(BDTestRun)Every executed scenario. Outlines appear once, with their rows in Examples.
GetNotRunScenarios(BDTestRun)IReadOnlyList<BDTest.Contracts.ScenarioDefinitionSummary> snapshots of chains that were built but not executed.
ClearScenarios(BDTestRun)Clears collected scenarios.
run.ReportId (on BDTestRun)The selected run's fresh report ID.
GetTestTimer(IReadOnlyCollection<ScenarioResult> scenarios)Start, finish and elapsed time for those scenarios; an empty collection has unset timestamps.
run.GetSnapshot()Immutable scenarios, pending definitions and run timing. For an empty run, Timer spans run creation through the current run clock.

Use it to build custom reports or to assert on results in a teardown:

Illustrative fragment
var run = BDTest.NUnitBDTestAssembly.GetRun(typeof(MyTests).Assembly);
var failed = BDTestUtil.GetScenarios(run).Where(scenario => scenario.Status == Status.Failed).ToList();

The immutable GetTestTimer overload accepts only the scenario collection; it has no report-timer argument. Use run.GetSnapshot().Timer when an empty run needs meaningful timing. See the complete explicit-run example.

Pending definitions​

BDTest.Contracts.ScenarioDefinitionSummary contains the scenario and story text, ScenarioId, ReportId, TestId, caller details, parameters, tags, test information, scenario Timeout, and Steps. Each StepDefinitionSummary contains StepType, unevaluated StepText and the step Timeout.

These are report snapshots, not fluent builders. Later changes to a chain do not change a previously returned summary. Taking a snapshot never invokes step delegates, WithArgs, WithStepText, table readers or doc string readers. Step text therefore retains its template placeholders until execution. Identify a pending chain by ScenarioId, not by builder object identity.

See definition migration for the change from BuildableTest.

Scenario and step model​

BDTest.Contracts.ScenarioResult is returned by BDTestAsync() and BDTestUtil.GetScenarios(run). Each call creates an immutable snapshot; query again after teardown to include later output. Results remain usable after clearing or disposing the run.

MemberDescription
StatusFinal status.
StepsIReadOnlyList<StepResult> for the final attempt.
StoryText, ScenarioTextResolved story and scenario text.
StartTime, EndTime, TimeTakenTiming of the final attempt.
ExceptionThe exception that ended the scenario, if any.
OutputConsole output from all steps.
TestStartupInformation, TearDownOutputSetup and teardown output.
CustomHtmlOutputForReportHTML added through ScenarioHtmlWriter.
CustomTestInformationCaptured information strings.
TagsTags.
RetryCount, AttemptsRetry history.
Timeout, TimedOutTimeout configuration and result.
IsOutline, Examples, ExampleValues, OutlineIdScenario outline data.
FrameworkTestId, FileNameThe test framework's ID and the source file.
Guid, ReportIdIdentifiers.
Snapshots expose no fixture, run, executable delegate or live runtime object.
Timestamps use UTC DateTimeOffset; see the result contract.

BDTest.Contracts.StepResult:

MemberDescription
StepTextText including the keyword, for example Given I have an account.
StatusStep status.
ExceptionAn immutable ExceptionInfo with type, message and stack trace.
OutputConsole output written during the step and its hooks.
StartTime, EndTime, TimeTakenTiming.
Timeout, TimedOutTimeout data.
IsRetryWhether the step ran in a retry.
DiagnosticsMessages about step text generation.
Guid, ScenarioId, ReportIdIdentifiers.

Step hooks receive the effective CancellationToken as a separate argument; it is not a member of StepResult. See cancellation and step hooks.

StepType values are Given, AndGiven, ButGiven, When, AndWhen, ButWhen, Then, AndThen and ButThen. AndWhen is appended as numeric value 8; existing numeric values are unchanged. It renders as And in reports.

BDTestContext​

BDTestContext (and BDTestContext<TContext> with TestContext) describes the running test. It is passed to ConfigureContext and is available on context base classes as BDTestContext.

MemberDescription
TestContextYour context object (generic version only).
TestBaseThe test class instance.
CurrentScenarioScenario?: the running scenario, or null before one exists, including while an outline row is being created.
CurrentScenarioBDTestExecutionIdThe execution ID.
ReportIdThe report ID of the test's run.
GetStoryText(), GetScenarioText()Story and scenario text.

Implementation helpers​

Text-generation helpers, version lookup, default constants and report JSON converters are internal. Use the public result APIs above and BDTestJsonHelper or BDTestJsonContext for serialization. The migration guide lists replacements for former direct helper calls.