Mostefai Mohammed Amine

Software and Cloud Architect

Amine
  • Contact
Previous Post
Next Post
Jun 11, 2020 .NET CoreWeb ApiTesting

Integration Tests Settings File Conflict (Appsettings.json)

Hi,

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()
              .UseEnvironment("Development")
              .UseConfiguration(Configuration)
              .UseStartup<TSTARTUP>());
        }

and when creating the configuration instance :

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

 

Enjoy !

Unit TestingIntegration Testing
Share This Post

Related posts

  • Integration Tests Settings File Conflict (Appsettings.json) Hi, One of the biggest issues when testing our .NET Core Web api apps is the conflict of appsetting...
  • Angular 2 + ASP.NET Core + SASS Starter Visual Studio 2015 Solution Hi, Angular 2 is a very promising framework and one of its biggest advantages is that it takes the p
  • Resolving the “Accessing referenced file from is not allowed” issue in Sharepoint Very often, Sharepoint publishing pages display the following message after modifying the master pag
Saving the comment

Cancel reply to comment

The captcha value you provided is incorrect.