Wednesday, March 28, 2012

Issue with Moles : Not able to read unit test configuration file when test case method is set to run under Moles host type.

 

While writing unit test cases using moles to create fake objects, I came across an issue where, test methods were not able to the configuration file provided for unit test case assembly. This issue was occurring only when the test method were marketed with HostType("Moles") attribute.  I verified the location of configuration file being used by checking the properties of AppDomain in which the test case method was running. Following is a screen shot of what I show.

 

clip_image001 

 

It is clear from screen shot that the AppDomain was setup to use "Microsoft.Moles.VsHost.x86.exe.config" configuration file instead of using configuration file generated for the unit test case assembly.

 

After performing some debugging , I could find out that the problem was with the moles executable which I had installed using standalone moles installer. When you install moles using in standalone installer, moles instrumentation runtime (Microsoft.Moles.VsHost.x86.exe)does not set the AppDomain to use right config file (test assembly config), Instead AppDomain is set to use the configuration file of moles runtime executable.

 

To resolve this issue , I installed moles using Pex installer (download). when you install moles using Pex installer, moles runtime executable does set AppDomain to use right configuration file (config file of unit test assembly). See the below screen shot , ConfigurationFile  property is now referring to unit test assembly's config file path.

 

clip_image002

 

 

Hence , using moles installed through Pex installer allows  the test cases to happily read the config information provided in test case assembly's config file.

No comments:

Post a Comment