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).
The following constructor parameters did not have matching fixture data:
WebApplicationFactory<Program> factoryCommon 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
- Declare
IClassFixture<TFactory>on the test class. - Use the same factory type in the class fixture and the constructor parameter.
- Reference the app entry type (
Program) so the factory can find it.
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.
// 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.