Skip to content
Latchkey

WebApplicationFactory "The following constructor parameters did not have matching fixture data" in CI

xUnit could not supply a constructor parameter of your integration test because the class does not implement IClassFixture<T> for that type, or the factory type does not match. Wire the fixture so xUnit injects the WebApplicationFactory.

What this error means

Integration tests fail to run with "The following constructor parameters did not have matching fixture data: WebApplicationFactory<Program> factory" (or your custom factory type).

.NET
The following constructor parameters did not have matching fixture data:
WebApplicationFactory<Program> factory

Common causes

The test class does not implement IClassFixture

xUnit only injects a fixture the class declares via IClassFixture<T>; without it, the constructor parameter has no source.

The fixture type does not match the parameter

The class declares IClassFixture<WebApplicationFactory<Program>> but the constructor takes a custom factory (or vice versa), so the types do not line up.

How to fix it

Implement IClassFixture with the exact type

  1. Declare IClassFixture<TFactory> on the test class.
  2. Use the same factory type in the class fixture and the constructor parameter.
  3. Reference the app entry type (Program) so the factory can find it.
ApiTests.cs
public class ApiTests : IClassFixture<WebApplicationFactory<Program>>
{
    private readonly WebApplicationFactory<Program> _factory;
    public ApiTests(WebApplicationFactory<Program> factory) => _factory = factory;
}

Expose Program to the test project

For a minimal-hosting Program.cs, make the entry point visible so WebApplicationFactory<Program> compiles.

Program.cs
// end of Program.cs
public partial class Program { }

How to prevent it

  • Match the IClassFixture type to the constructor parameter type.
  • Expose Program (public partial class) for WebApplicationFactory.
  • Share one custom factory type across integration tests.

Frequently asked questions

What causes ""constructor parameters did not have matching""?
xUnit only injects a fixture the class declares via IClassFixture<T>; without it, the constructor parameter has no source.
How do I fix "constructor parameters did not have matching"?
Implement IClassFixture with the exact type

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card