liveBook · Manning

Test result attachment

As explained in Effective Behavior-Driven Development

A file or other item registered with a test result so it can be inspected alongside the test outcome.

A test result attachment is supplementary information registered with a test outcome so it can be inspected during diagnosis. Saving a file to the test output directory usually does not attach it; the scenario automation tool or test framework must register it. section 19.2

A practical failure-only pattern is to:

  • Use an after-scenario hook, which runs after execution even when a scenario fails. section 19.2
  • Check the scenario status, save useful diagnostic information when it failed, and register the saved file as an attachment. section 19.2
  • Attach application logs or, for UI automation, screenshots that may help reveal UI issues or timing problems. section 19.2
Listing 19.4 Save and register supplementary attachment
*** Support/Hooks.cs ***
[Binding]
public class Hooks(
    IScenarioContext scenarioContext,    #A
    IReqnrollOutputHelper outputHelper,    #B
    AppLogContext appLogContext)    #C
{
  [AfterScenario(Order = 0)]    #D
  public void SaveAppLogOnError()
  {
    if (scenarioContext.ScenarioExecutionStatus == 
        ScenarioExecutionStatus.TestError)    #E
    {
      string outputPath = Path.GetFullPath(
        $"app-log-{Guid.NewGuid():N}.txt");    #F
      appLogContext.SaveToFile(outputPath);    #G
      outputHelper.AddAttachment(outputPath);    #H
    }
  }
}

The example saves an application log after a failed scenario and registers it with Reqnroll's output helper. section 19.2

How Effective Behavior-Driven Development covers it

How deep it goes
Demonstrates a failure-only hook workflow and Reqnroll registration; framework-specific APIs are left to their documentation.
Examples
Uses application logs and UI screenshots as diagnostic attachments.
What it assumes
Assumes familiarity with scenario execution status and after-scenario hooks.
What you can do after
Apply it via Reqnoll by saving and registering a file after a scenario fails.
How it connects
Connects scenario hooks with test frameworks and test reports.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Effective Behavior-Driven Development. The section links point to the parts of the book it draws on.