Skip to content

Instantly share code, notes, and snippets.

@martincostello
Created February 26, 2016 15:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save martincostello/d1130f542106ce4d4538 to your computer and use it in GitHub Desktop.
Save martincostello/d1130f542106ce4d4538 to your computer and use it in GitHub Desktop.
BenchmarkDotNet Logger for Xunit
namespace MartinCostello
{
using BenchmarkDotNet.Loggers;
using Xunit.Abstractions;
/// <summary>
/// A class that writes output to the test output for Xunit. This class cannot be inherited.
/// </summary>
public sealed class XunitTestOutputLogger : ILogger
{
/// <summary>
/// The <see cref="ITestOutputHelper"/> in use. This field is read-only.
/// </summary>
private readonly ITestOutputHelper _helper;
/// <summary>
/// Initializes a new instance of the <see cref="XunitTestOutputLogger"/> class.
/// </summary>
/// <param name="helper">The <see cref="ITestOutputHelper"/> to use.</param>
public XunitTestOutputLogger(ITestOutputHelper helper)
{
_helper = helper;
}
/// <inheritdoc />
public void Write(LogKind logKind, string format, params object[] args)
{
_helper.WriteLine(format, args);
}
}
}
@martincostello
Copy link
Author

Obviously requires you to have BenchmarkDotNet and Xunit first:

Install-Package BenchmarkDotNet
Install-Package Xunit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment