We use the very useful Gallio unit testing framework for both our C# and C++/CLI unit tests. We then use Resharper to execute the C# tests within Visual Studio [remember to reinstall Gallio after you have installed Resharper].
But ReSharper does not work with C++/CLI so it is more difficult to run the tests within Visual Studio. Obviously the test projects produce XXXTests.dll assemblies which cannot be run directly by selecting the projects to be the "Start Up" project and pressing F5. It is possible to set the debugging properties on the project to use Gallio.Echo.exe to be the program launched by VS when F5 is pressed, passing it the test assembly name as the command line argument. This now allows you to press F5 and see all of your tests run. There are two problems with this, firstly the Command window in which they run closes at the end of the run, making it more difficult to see what passed and failed. Secondly, even though you have asked it to run in the debugger, it won't stop on any breakpoints you have set!
The way to overcome the first issue, if it is important to you, is to use the logging command line arguments and get it to log to file what has happened.
The way to overcome the second issue, which is the main reason we want to run our tests in VS to begin with, it to add the following command line argument:
/r:IsolatedAppDomain
I have no idea what this does (other than run the test in it's own app domain?), but the upshot of it is that the breakpoints become enabled and you can now debug your tests in VS. I'd have thought having a command line option "/r:EnableDebugging" or similar would be more obvious, even if all it did was set the AppDomain flag internally?
This also works well for C# projects where you do not have Resharper or TestDriven.Net.
Example command line:
"C:\Program Files\Gallio\bin\Gallio.Echo.exe" SomeUnitTests.dll /r:IsolatedAppDomain
Subscribe to:
Post Comments (Atom)

5 comments:
The default behavior is to run tests in their own process. It is more robust but it makes debugging significantly more challenging since the debugger must attach to the host process. Using IsolatedAppDomain disables the creation of a separate process.
I am trying to debug a test in VS2008 using latest Gallio.
Can you explain how one would add /r:IsolatedAppDomain to the command line?
I have tried, adding it in command line args of my Test project.
I have tried the full line in "start with external program".
None of which work.
Basically I've done everything inside VS, and I've got a test project that runs nice on F5, but breakpoints are ignored.
Are you using Icarus to run your tests or some other tool?
Here's the rundown of how to debug:
Using Icarus: Click the new "Debug" button in v3.0.6.
Using VS Team Test: Select the tests in the Test View and click Debug.
Using TestDriven.Net: Right-click on a test or fixture and select "Test With... Debugger"
Using ReSharper: Select a test in the editor or test session view and use the Debug drop-down or toolbar button as appropriate.
Using Echo from command-line: Run tests with /debug argument. This will automatically attach to Visual Studio (or launch it if it is not running).
Using PowerShell, NAnt or MSBuild, similar instructions to Echo. Use "DebugTests" switch, debug="true" attribute, or Debug="true" attribute respectively.
Alan, it sounds like the changes in 3.0.6 make my method obsolete, we're are using 3.0.5 where we don't have the /debug flag for Echo. That would very useful to us!
Thanks for that.
I have added /debug to the command line for echo and it does run under VS and does hit break points. Thanks very much.
Post a Comment