views:

131

answers:

2

I've just started using Pex to generate parameterized unit-tests for my project. However, when I let Pex run its explorations, my code crashes because it cannot read from the web.config (ConfigurationSettings.AppSettings has zero elements to be more precise). The working-directory during the explorations is: "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE". I assume this is the root-cause.

I know that the supposedly proper way to handle this is to create mock-objects corresponding to the values I need. However, this would force me to create tons of mock-code and wouldn't provide any tangible value IMHO, because I have no problem bundling web.config with the test-project.

How do I enable reading from web.config (or app.config) while the Pex explorations executes?

+3  A: 

You've answered your own question I'm afraid - you wouldn't directly access your database from your code, so why do it with your config files? Just put a thin wrapper around your config file settings and stub it out in your tests. You don't have to do it all in one go, start with the piece of code under test and move the direct references behind your wrapper bit by bit. The tangible benefit of doing this is that it makes testing easy.

Also, with Pex if your code is getting fully torn down between each run (depends on your code and the tests whether or not this is actually the case) you'll be hitting the file system each time which will have a serious impact on performance.

FinnNk
+1  A: 

The Pex developers don't read (often) stackoverflow. You better ask your Pex-related question on the forums at http://social.msdn.microsoft.com/Forums/en/pex/threads

Peli