Search code examples
c#asp.net-core-webapixunit.net

Output Test results XUnit .net core when using IClassFixture


I used Nunit all the time and now moved to XUnit.

I use ITestOutputHelper successfully when I do not implement IClassFixture, e.g.:

public myClassTest(ITestOutputHelper outputHelper)
{
    this.outputHelper = outputHelper;
}

However when I implement IClassFixture I cannot find a way to inject ITestOutputHelper.

Sample where I cannot Implement ITestOutputHelper

public class MyIntegrationTests : IClassFixture<TestServerFixture<Startup>>
{
    public MyIntegrationTests (TestServerFixture<Startup> testServerFixture)
    {
        client = testServerFixture.Client;
    }
}

Am I missing the obvious?


Solution

  • It should Just Work by doing:

    public class MyIntegrationTests : IClassFixture<TestServerFixture<Startup>>
    {
        public MyIntegrationTests (TestServerFixture<Startup> testServerFixture, ITestOutputHelper outputHelper)
        {
            client = testServerFixture.Client;
            this.outputHelper = outputHelper;
        }
    }
    

    as ITestOutputHelper, and all declared Class and Shared fixtures can get provided in this way.

    What message are you being given in the Output window (Ctrl-Alt-O)'s Tests panel ?