Xunit The following constructor parameters did not have matching fixture data

xunit lifetime
xunit before all tests
assembly fixture xunit
xunit test lifecycle
xunit class data
fixture class c#
xunit test base class
xunit reset static class

I keep getting this error while using xunit for .NET 1.0 framework net46.

The following constructor parameters did not have matching fixture data

I have seen this post: Collection fixture won't inject and followed the instructions regarding collection fixture closely as described here:

http://xunit.github.io/docs/shared-context.html#collection-fixture

Nothing seems to work.

Any suggestions to what might cause this?

In my case it turned out to be a matter of doing it right according to the instructions. By mistake I had annotated the class with

 [Collection("ProjectCollection")]

instead of:

 [Collection("ActorProjectCollection")]

I must say that the dependency injection mechanism of XUnit would be greatly improved if the error messages gave more explicit hint of what is wrong.

Xunit The following constructor parameters did not have matching , I keep getting this error while using xunit for .NET 1.0 framework net46. The following constructor parameters did not have matching fixture data. I  Even with optional params error: "The following constructor parameters did not have matching fixture data: " #985 NinoFloris opened this issue Sep 24, 2016 · 1 comment

Another scenario in which this might fail is if the [CollectionDefinition] is defined on a type outside the executing test assembly. The attribute itself needs to be defined inside of it or xUnit won't pick it up.

xunit constructor parameter exception did not have matching fixture , "The following constructor parameters did not have matching fixture data: IUserService userService, HomeController homeController, ILogger`1  Injects the context into to the test fixture; or; Throws The following constructor parameters did not have matching fixture data: ILogger, DBAccesswhere those two types are registered with SI and are listed in the fixtures constructor; To work around this my context provides the container as a property to request the necessary dependencies.

This exception may arise when the constructor of your fixture class is failing due to some other problem, in my case connecting to a local Mongo server.

Either look for other failures and solve those first or lighten your constructor up so it does less.

Exception if fixtures have more than one constructor with arguments , DatabaseFixture' may only define a single public constructor.) (The following constructor parameters did not have matching fixture data:  (Class fixture type Tests.DatabaseFixture' may only define a single public constructor.) (The following constructor parameters did not have matching fixture data: DatabaseFixture dbFixture) ---- Class fixture type 'Tests.DatabaseFixture' may only define a single public constructor.

It happened to me a couple of times just after adding the Collection and the CollectionDefinition decorators and I always arrive to this answer when looking on Internet.

But in my case the problem was just that it seems that a 'Clean Solution' action is needed before testing whether it works or not. Without cleaning the solution I always get a The following constructor parameters did not have matching fixture data error.

So, I write also this answer in order to help my future self.


Anyway, in order to avoid the problem explained by Nikola Schou, you can always use a constant to avoid name mistmatching:

public static class Collections
{
    public const string ActorProjectCollection= "ActorProjectCollection";
}

-

[Collection(Collections.ActorProjectCollection)]
/// ...

-

[CollectionDefinition(Collections.ActorProjectCollection)]
/// ...

I am getting following error : “The following constructor parameters , I am getting following error : “The following constructor parameters did not have matching fixture data: AddressValidator addressValidator” - xunit. The following constructor parameters did not have matching fixture data: IntegrationTestFixture fixture. This seems to happen regardless of whether I'm using xUnit Facts or Theories, or which test runner I'm using.

In my case I had to implement the IClassFixture<> interface on the test class.

public class MyTests : IClassFixture<QueryTestFixture>

After I moved the QueryTestFixture to another project the Class attribute stopped working

[Collection("QueryCollection")]

Which was linked to the implementation in the fixture class (see below)

[CollectionDefinition("QueryCollection")]
public class QueryCollection : ICollectionFixture<QueryTestFixture> { }

I had tried many alternative ways to solve this but ended up reading the xunit.net explanation about shared context. which provided a solution.

xUnit Collection Fixtures - Build/Test Issues, Code: Xunit.Sdk.TestClassException: The following constructor parameters did not have matching fixture data: DatabaseFixture fixture. following constructor parameters did not have matching fixture data : DbContextOptions'1options 15 Net Core: Execute All Dependency Injection in Xunit Test for AppService, Repository, etc

Unit Testing xunit The following constructor parameters did not have , The following constructor parameters did not have matching fixture data for unit testing using moq and xunit. Already using dependency  To use class fixtures, you need to take the following steps: Create the fixture class, and put the startup code in the fixture class constructor. If the fixture class needs to perform cleanup, implement IDisposable on the fixture class, and put the cleanup code in the Dispose() method. Add IClassFixture<> to the test class.

Shared Context between Tests > xUnit.net, Constructor and Dispose (shared setup/cleanup code without sharing object To use class fixtures, you need to take the following steps: Db = new SqlConnection("MyConnectionString"); // initialize data in the test database . It will do this whether you take the instance of the class as a constructor argument or not. Result Message: The following constructor parameters did not have matching fixture data: DatabaseFixture2 configure. What version of xunit are you using? I'm using 2.0.0.2738 from the nuget pre-release. Am I missing some other type of configuration? I will pull down the source tomorrow and try and see where that string is thrown.

xUnit, The following constructor parameters did not have matching fixture data. assembly fixture xunit fixture class c# had one or more unresolved constructor  If I have random Exception in MyFixture then all classes will not get a MyFixture object. Example below will describe what I mean. First class should be created succesfoully and second should throw exception, but both throw exception.

Comments
  • This happened to me. The class defined by CollectionDefinition and Collection have different namespaces.
  • I had the same issue. I couldn't execute multiple tests at once after refactoring my fixtures (they worked if i ran them one by one). After a clean up in VS it worked fine.