Each one of my XUnit test projects has an appsettings.json file that specifies a few settings. I have always used dependency injection with IConfiguration to retrieve these settings in my Test Fixture class. Now that I think about it I have absolutely no idea how the IConfiguration was resolved in the past since there is no Startup.cs and ConfigureServices methods in an XUnit project. But I swear it worked.
The following used to work and now it does not:
Fixture:
public class TestFixture : IDisposable
{
public IConfiguration Configuration { get; set; }
public TestFixture(IConfiguration configuration)
{
Configuration = configuration;
}
}
Test Class:
public class TestCases : IClassFixture<TestFixture>
{
public TestCases(TestFixture fixture)
{
}
}
The error I am receiving is the following:
Message: System.AggregateException : One or more errors occurred. ---- Class fixture type 'MyProj.Tests.TestFixture' had one or more unresolved constructor arguments: IConfiguration configuration ---- The following constructor parameters did not have matching fixture data: TestFixture fixture
IClassFixture
and/orCollectionAttribute
usage. The only thing that's popping into my head is a default constructors hiding the dependencies and/or test classes being private etc. but assume something did work for you so it must be something else – Rorke