Cannot Use ConfigurationManager inside Unit Test Project

后端 未结 5 1795
孤独总比滥情好
孤独总比滥情好 2021-01-07 19:20

I\'m trying to write a unit test for my project, but it will not let me use the Configuration Manager. Right now my project is set up like

ASP.Net application (all a

5条回答
  •  既然无缘
    2021-01-07 20:06

    You are doing a unit test and in unit test your concentration should be the particular method trying to test and should remove extraneous dependencies. in this case, try mocking/moleing(use Microsoft Mole and Pex) system.configuration class; that will give a solution for sure.

    What I am saying, once you install MS moles-and-pex -> in your test project solution -> right-click the system assembly and choose create mole.

    That will give you a mole'ed version of configuration class which in turn will have a mocked version of configuration class -- using which you can bypass the problem you are facing.

提交回复
热议问题