Skip to content

Logging adapter to capture output sent to Microsoft's standard ILogger and redirect to each test case's results

License

Notifications You must be signed in to change notification settings

GivePenny/GherkinSpec.Logging

Repository files navigation

GherkinSpec.Logging

Overview

A bridge package that allows the subject-under-test in GivePenny GherkinSpec test projects to log to Microsoft's Microsoft.Extensions.Logging.Abstractions.ILogger and for those messages to be routed through to the test output/results.

See the GivePenny GherkinSpec project for background information.

Using this package

Reference the GivePenny.GherkinSpec.Logging package in your test project, then modify your project's [BeforeRun] hook to make sure that the following lines are all included:

// Namespaces at the top ...
using GivePenny.GherkinSpec.Logging;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;

// ... then inside the [BeforeHook] method ...
var services = new ServiceCollection();
testRunContext.ServiceProvider = services
    .AddSingleton(testRunContext.Logger)
    .AddLogging(
	    builder => builder.AddTestLogging(testRunContext.Logger))
    .BuildServiceProvider();

// ... then your steps class constructor ...
public MyStepsClass(ILogger<MyTestSubject> logger)
{
    // Use the logger instance, maybe assign to a private field and use inside steps when the MyTestSubject class is instantiated.
}

Useful References

About

Logging adapter to capture output sent to Microsoft's standard ILogger and redirect to each test case's results

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages