For the upcoming MSBee shared source release, I've spent time migrating our unit tests from MSTest to NUnit since NUnit is freely available to the developer community. MSTest and NUnit have similarly named attributes and Assert methods, which helped make the migration trivial.

Although I'm not trying to stir the pot, I feel like mentioning that after using NUnit, I still prefer MSTest. Some reasons include:

  • Integration within the VS IDE
  • Just one click to run tests under a debugger
  • VS can generate accessors, for private variables, to be used in test methods

While I'm not interested in debating these assertions (at least not in this post), the first point is of interest to me in this post. While developing MSBee, I wanted to have some integration between the VS IDE and the NUnit GUI for running our tests. After reading the NUnit 2.2.7 documentation, I followed the instructions to add nunit-gui.exe as a custom tool in the VS IDE. I'm using $(TargetPath) for the arguments and $(TargetDir) for the initial directory. Unfortunately, when I tried running NUnit via the Tools menu, I received a delightful FileNotFoundException: Couldn't load nunit.framework or one of its dependencies. After doing some reading in the NUnit forums, a few others appeared to be hitting the same issue although no workarounds were posted. If I remember correctly, someone attributed the problem to NUnit searching the obj directory instead of the bin directory when using the Target macros. Whether this behavior is being caused by NUnit or VS is unclear.

I've tried working around this with different macros and thought I succeeded by setting $(ProjectFileName) for the arguments and $(ProjectDir) for the directory. While this did cause my tests to run, I recently realized that when I change to a different build configuration and re-run NUnit, it runs the test DLL in the previous configuration's bin directory. Presumably, the Target macros would solve this problem, provided that they worked. I later tried using other VS macros, including $(OutDir) or $(Configuration); I hoped I could append them after $(ProjectDir) to build a path to the bin directory. This time, I was hit with the bitter taste of an ArgumentException that specified illegal characters in path.

Since I want some Test GUI integration in my IDE, I'll continue to stubbornly attempt to get NUnit to load my real target path. If anyone else has experienced this problem, or knows a workaround, feel free to post a comment. BTW, I realize I could use tools like TestDriven.NET to provide IDE integration. However, at this point, I really want to force VS and NUnit to obey me, hence I'm looking for a resolution to this particular problem.