Is is possible to have ITestOutputHelper created by xUnit to be available in AutoFixture context?
In my integration tests I use Builder class that contains helper methods for some routine operations. In order to hide complexity of class creation I use custom AutoDataAttribute, so my tests are getting created object as test method parameter from AutoFixture.
Now I decided to add some logging functionality to Builder and can't find out how to pass ITestOutputHelper into Builder constructor from custom AutoDataAttribute.
using Ploeh.AutoFixture;
using Ploeh.AutoFixture.AutoNSubstitute;
using Ploeh.AutoFixture.Xunit2;
using Xunit;
using Xunit.Abstractions;
namespace XunitAutoFixtItestOutput
{
public class Class1Tests
{
private readonly ITestOutputHelper _output;
public Class1Tests(ITestOutputHelper output)
{
_output = output;
}
[Theory, DefaultAutoData]
public void UnitOfWork_StateUnderTest_ExpectedBehavior(Builder builder)
{
}
}
public class Builder
{
private readonly ITestOutputHelper _outputHelper;
public Builder(ITestOutputHelper outputHelper)
{
_outputHelper = outputHelper;
}
public void DoSomething()
{
_outputHelper.WriteLine("Something happened");
}
}
public class DefaultAutoData : AutoDataAttribute
{
public DefaultAutoData() : base(new Fixture().Customize(new DefaultCustomization()))
{
this.Fixture.Customize<Builder>(f => f.FromFactory(new Builder(??Where to get it from??)));
}
}
public class DefaultCustomization : CompositeCustomization
{
public DefaultCustomization() : base(new AutoConfiguredNSubstituteCustomization())
{
}
}
}
ITestOutputHelper
instance that gets passed to the test class' constructor. I don't have the full view of what xUnit.net's API enables you to do, but unless it provides an extensibility point that enables you to get the injectedITestOutputHelper
whenDataAttribute.GetData
is invoked, I don't think this is possible... – Yacketyyak