Skip to content
suremaker edited this page Jul 2, 2023 · 13 revisions

Page version: 3.x / 2.x / 1.x

Default report generation

After all tests are finished, the feature report files will be created in project output directory (usually bin\debug or bin\release). By default, "Reports\FeaturesReport.html" file will be created (or "Reports/FeaturesReport.html" on Unix systems).

The HTML report is designed for readability and can be used to present the test outcome to the business.

Report generation configuration

It is possible to alter default behavior and customize format and location of the reports or even use own reporting mechanism. The LightBDD configuration mechanism is described in LightBDD Configuration section. It is possible to customize report generation with following code:

configuration
	.ReportWritersConfiguration()
	.Clear()
	.AddFileWriter<XmlReportFormatter>("~\\Reports\\FeaturesReport.xml");

It is worth to mention that:

  • the relative paths are resolved against working directory at startup of the LightBDD tests,
  • the paths starting with root directory will be expanded with working directory drive under Windows (i.e. \temp\output.html will be resolved to d:\temp\output.html if the working directory drive letter is d:\),
  • the UNC paths (i.e. \\machine\directory\file.html) are preserved,
  • the absolute paths are preserved,
  • the ~ represents AppContext.BaseDirectory and it is suggested to use in configured paths, as the test runners may not set current working directory properly.

Finally, the specified directory will be automatically created if does not exist yet.

Please note that ReportWritersConfiguration has Add(IReportWriter) method allowing to specify custom report writers that not necesarily have to be file related.

Supported report formatters

Currently, LightBDD framework offers following types of IReportFormatter implementations, that can be used for report formatting:

  • LightBDD.Framework.Reporting.Formatters.XmlReportFormatter (see example file),
  • LightBDD.Framework.Reporting.Formatters.PlainTextReportFormatter (see example file),
  • LightBDD.Framework.Reporting.Formatters.HtmlReportFormatter (see example file).

Example projects using various report generators

Please browse examples directory to see how example projects generate reports.

Parameterizing report file output path

It is possible to parameterize the output path of the report to include such information like time when tests were executed. The parameters of {name:format} format can be specified in path, where name is parameter name and format is a Format String Component used by String.Format() method.

Currently, a following parameters are supported by default:

Name Type Description
CurrentDateTimeUtc DateTime equivalent to DateTime.UtcNow
CurrentDateTime DateTime equivalent to DateTime.Now
TestDateTimeUtc DateTime UTC date/time when test execution started
TestDateTime DateTime local date/time when test execution started

Please note that it is possible to configure more parameter types by using ReportFileWriter constructor allowing to specify ReportPathFormatter.

The example usage of that feature is presented here.

Post-processing generated reports

The reports are generated during LightBDD engine disposal which happens after LightBddScopeAttribute.OnTearDown() method is executed (in the integrations having such class - see LightBDD Configuration for details). It means that LightBddScopeAttribute.OnTearDown() cannot be used to post-process the generated reports.

As of LightBDD version 2.3.X, if generated reports have to be post-processed (for example sent via email), there are 2 methods to do it:

  • process test reports as a separate build script step, after test process is finished,
  • implement a custom decorating proxy IReportWriter report writer that delegates report creation to injected writers and process reports produced by them.

Example custom writer:

class MyEmailingReporter : IReportWriter
{
    private readonly ReportFileWriter[] _writers;

    public MyEmailingReporter(params ReportFileWriter[] writers)
    {
        _writers = writers;
    }
    public void Save(params IFeatureResult[] results)
    {
        foreach (var writer in _writers)
            writer.Save(results);

        SendEmail(_writers.Select(x => x.FullOutputPath).ToArray());
    }

    private void SendEmail(string[] attachmentPaths)
    {
        // send email
    }
}

Example registration:

protected override void OnConfigure(LightBddConfiguration configuration)
{
    configuration
        .ReportWritersConfiguration()
        .Clear() // remove defaults
        .Add(new MyEmailingReporter(
            new ReportFileWriter(new HtmlReportFormatter(), "~\\Reports\\HtmlReport.html"),
            new ReportFileWriter(new XmlReportFormatter(), "~\\Reports\\XmlReport.xml")
            ));
}

Continue reading: Execution Time Measurement

Clone this wiki locally