ConfigurationManager.AppSettings Returns Null In Unit Test Project

前端 未结 4 439
故里飘歌
故里飘歌 2021-02-05 05:47

I have a C# unit test project with application settings in the app.config file. I am testing a class that exists in a different project. That class depends on bot

4条回答
  •  花落未央
    2021-02-05 06:29

    And then he screamed "NOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO".

    Cite: I have a C# unit test project with application settings in the app.config file. I am testing a class that exists in a different project. That class depends on both, ConfigurationManager.AppSettings and ConfigurationManager.ConnectionStrings.

    You don't do this. EVER!!!! Why? because you have now created a dependency. Instead, use dependency injection so the class can do its work without having to peak into the configuration file that belongs to the application.

提交回复
热议问题