Tuesday 13 January 2009

Debugging Gallio tests in Visual Studio

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



4 comments:

Alan Evans said...

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.

Colin said...

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!

Alan Evans said...

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.

Sergiy Tkachuk said...

/r:Local allows to trace as well