Mostefai Mohammed Amine's Blog


Hi and welcome to my blog. I share in this space a lot of posts related to software architecture, and software development. Content is mainly related to .NET CORE development, Angular, Sharepoint, Azure and Office 365. I hope that my articles are helpful and that you enjoy using them 😉

Integration Tests Settings File Conflict (Appsettings.json)


One of the biggest issues when testing our .NET Core Web api apps is the conflict of appsettings.json files between the main project and the testing project.

One of the solution is to copy always the appsettings files belonging to the test project. But this solution is not that perfect. When forgetting to do so, the test engine behaves strangely.

One of the solution I have adopted is pretty straightforward ! Use a different name for the settings json and use this file when doings tests. That’s pretty much it.

Took a look at the code snippet below when creating an instance of “TestServer" :

   protected TestServer CreateServer<TSTARTUP>()
            where TSTARTUP : class
            return new TestServer(new WebHostBuilder()

and when creating the configuration instance :

  var builder = new ConfigurationBuilder()
                .AddJsonFile(configPath, optional: true, reloadOnChange: true);
            Configuration = builder.Build();


Enjoy !