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
