I asked another question here:
http://forum.ncrunch.net...project-under-test.aspx
and got lots of valuable information. My question here is somewhat related but different enough that I felt it warranted a separate post.
I have added a test project to a solution given to me and wrote a very simple unit test. I can't easily modify the rest of the solution which uses lots of absolute paths instead of project references. I'm only adding a UnitTest dll. It would not pass with MSTest or NCrunch. It then passed AFTER I changed the output path of the UnitTest dll to be the same absolute path as the output path for the application under test.* This seems reasonable, the unit test dll has need of the same references as the app under test. Forcing the unit test dll to the same place as the main app allows it to find all those pesky references. I should mention that some of these references are just dlls. No source code.
The error I got until I made this fix was
System.TypeInitializationException: The type initializer for 'Frame.Presenters.MainWindowPresenter' threw an exception. ---> System.IO.FileNotFoundException: Could not load file or assembly 'ABC.dll' or one of its dependencies. The specified module could not be found.
at Frame.Presenters.MainWindowPresenter..cctor()
--- End of inner exception stack trace ---
at Frame.Presenters.MainWindowPresenter..ctor()
at FrameUnitTests.MainWindowPresenterTests.MainWindowPresenterTest() in C:\SVN\Frame_Mike\FrameUnitTests\MainWindowPresenterTests.cs:line 14#0
I believe the key problem is that this main project under test. "Frame" has absolute reference (not project reference and not relative references!) to stuff in:
C:\CompanyName\bin\Frame\3.0\Debug\ABC.dll
I can't easily change the structure of the solution, I'm simply adding a unit test project to it. Furthermore I should state that there is not code associated with ABC.dll, it is simply a dll that Frame project references.
As I said, I "fixed" the problem by making the output path for the unit test dll go to C:\CompanyName\bin\Frame\3.0\Debug. This isn't perfect though because I have to disable NCrunch to do a rebuild due to NCrunch and MSBuild conflicing (again see previous post if you are interested). In the referenced previous post it was suggested to have different output paths, one for the main build and one for NCrunch. Something like:
<OutputPath Condition="'$(NCrunch)' == '1'">bin\</OutputPath>
<OutputPath Condition="'$(NCrunch)' != '1'">$(OUTDIRECTORY)</OutputPath>
I tried this, but it doesn't seem to work here. If you let NCrunch put the unit test dll local, it doesn't know about all those references in: C:\CompanyName\bin\Frame\3.0\Debug I even tried have to paths for the project under test. Again, no luck. In this case, where I can't modify the solution and am just adding a unit test project it seems like the solution would be to use two above paths as described above (so rebuild alls can be done without disabling NCrunch) and also have a way of telling NCrunch, "oh by the way, all the references you need can be found in C:\CompanyName\bin\Frame\3.0\Debug".
Is there a way to do such a thing?
Thanks,
Dave
*For full disclosure I should mention that simply running the test from Test Explorer (i.e. no NCrunch was failing) until I changed Test->Test Settings->Default Processor Architecture to x64. After that no problems. Suspecting that might be NCrunch's problem too, I changed "Use CPU architecture" under NCrunch settings to "x64". No difference.
Edit...
I should also mention that with my "fix", besides the problem of rebuild all, the code coverage is not working. I.e. no stats on amount of code covered by tests.