How to use web.config when unit testing an asp .net application

后端 未结 6 1285
我寻月下人不归
我寻月下人不归 2020-12-08 01:55

I am starting out with unit testing, I have a method that uses the web.config for a connection string.

I was hoping to be able to use

[DeploymentItem         


        
6条回答
  •  爱一瞬间的悲伤
    2020-12-08 02:08

    If you need a connection string, you are not writing a unit test (assuming that you are using the connection string for going to database). Unit tests are not supposed to interact with outside environment. You will want to run all of them after each check in so they better run at the speed of light.

    For a unit test, you will want to isolate your code from your database. Modify your tests (and the code you are testing if necessary) so that you will not need to go to database for testing them.

提交回复
热议问题