Yesterday I spent 4+ hours trying to tackle a bug that should not have been a bug in the first place, and the culprit was MSTest. Please keep in mind that I have never really used MSTest in any real form. I am a NUnit guy through and through.
Here is some background on what I was trying to do (keep in mind, I have done this numerous times in the past). I was setting up an application that was going to use the StructureMap Ioc/DI (Version 2.4.9 -- aka 2.5) container. Because I do not mind using the attributres and StructureMap.config files this was the way I was going to do all the wiring for my container.
During the testing (via MSTest) of this code, I immediatly ran into an issue with the .config file not being found at runtime. Now this was odd to me as I could see that the .config file was being copied to the output directly like it should be. I spent the next 20-30 minutes ensuring that all my code was correct and that the config file was indeed in the right place.
It was not till I was stepping though the current directory was not my /bin folder, but rather \TestResults\whitt010_CM4NRG1 2008-07-22 16_18_25\out (if you have ever used MSTest you will understand the folder naming convetion). I found this to be very, very odd. I did a little digging and realized that for each test run MSTest will create a new folder to run all the tests in (why, I have now figgen clue). But because my .config file was not a 'normal' file in the eye of MSTest it was not being copied. Well, my good buddy Steven Andrews was nice enought to help me figure out how to copy the .config file to the correct output folder (post on that forthcoming). Well, I thought this would solve my issue, but it did not.
Now that I have the .config in the correct test folder (again, not in the bin like ALL the other testing frameworks..why does MS always have to be different) I thought I would be golden. However, I was still not able to get this working. After another hour or two of beating my head against the wall, and of bothering both Chad Myers and Jeremy Miller (father of StructureMap). I finally realized what was going on. When MSTest runs, it sets the current working directory to c:\<InstallBase>\Microsoft Visual Studio 9.0\Common7\IDE because that is where MSTest runs. Because of this StructureMap was having issues finding the .config file (before you jump to SM as being the issue, think again. I have done this before both with NUnit and MBUnit and both work fine).
Alas after 4+ hours into my journey I threw in the towel. I decided that using the StructureMap.config file method with MSTest was just too much friction. So again with the help of Jeremy and Chad (do not know who was actually typing in the IM window as they were both there) I decided to solve the problem another way.
Here is what I did to get everything working:
- Download and use StructureMap 2.4.9 (aka 2.5)
- No-longer used the StructureMap.config file.... bye bye my friend
- Setup StructureMap to read my config info from my app.config
- This involves moving my config info to the app.config
- Telling StructureMap how to read from the app.config (blog post on this soon)
- Swore over and over again at the pain that MSTest caused me.
In intend to create a few more detaild posts on this over the next few days and will links to them here.
Hope this helps someone.
Till next time,
[----- Remember to check out DimeCasts.Net -----]
07-23-2008 9:28 AM