Cannot Use ConfigurationManager inside Unit Test Project

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.


It could be one of several issues:

  1. You didn't add app.config to your ProjectTest project.
  2. You didn't add connection string in your app.config.