Reading from web.config when running Pex research

I just started using Pex to create parameterized unit tests for my project. However, when I let Pex run its investigations, my code crashes because it cannot read from the web.config (ConfigurationSettings.AppSettings has more zero elements, to be more precise). Working directory while researching: "C: \ Program Files (x86) \ Microsoft Visual Studio 9.0 \ Common7 \ IDE". I guess this is the main reason.

I know the supposedly correct way to handle this is to create mock objects that match the values ​​you want. That said, it would have forced me to create tons of mock code and would not provide any tangible value IMHO, because I have no problem with the web.config bundle with the test project.

How do I enable reading from web.config (or app.config) while doing Pex research?

+2


source to share


2 answers


You answered your own question, I'm afraid - you wouldn't be able to directly access your database from your code, so why do that with your config files? Just put a thin wrapper around your config file settings and dip it into your tests. You don't have to do everything in one go, start with the piece of code under test and move the direct links differently behind your wrapper. The tangible benefit of this is that it makes testing easier.



Also, with Pex, if your code is completely torn between each run (depending on your code and tests, whether or not this is the case), you will hit the filesystem every time, which will have a serious performance impact.

+3


source


Pex devs don't (often) read stackoverflow. Better ask your Pex related question in the forums http://social.msdn.microsoft.com/Forums/en/pex/threads



+1


source







All Articles