app.configs and MSTest Project - null reference for a connection string

后端 未结 3 1695
故里飘歌
故里飘歌 2021-01-12 03:11

When I try to run Unit Tests (mstest) I run into this issue.
The line of code:

_mainCnStr = System.Configuration.ConfigurationManager.
               C         


        
3条回答
  •  被撕碎了的回忆
    2021-01-12 03:26

    One thing to watch with MSTest (from the IDE at least); it doesn't run the tests in the regular output (bin) folder, and it doesn't respect the project's file inclusions ("Copy to Output Directory"). You often need to explicitly tell it (MSTest) which files to put into the test area. You will need to include the "app.config" in this list; either via the testrunconfig ("Deployment"), or by adding an attribute ([DeploymentItem]) to the affected test fixtures.

提交回复
热议问题