Tips & Tricks: Set the output type to EXE and give it a main method


Ok, you’ve written your tests, and you want to debug them or you’ve got a test failing and you can’t quite see why. What are you gonna do? Well, right now we don’t have built in support for debugging of tests, but there is a sneaky workaround that I use a lot.


 


Because all our projects are just derivatives of the normal projects, you can set the same options. This means that you can turn the project into an EXE type rather than just a class library. Because it’s an EXE you can create a main method and allow F5 execution. Because the unit test framework works with any ol’ assembly you can still execute the tests from test view, even with a EXE rather than DLL.


 


One other sneaky trick I’ve thought about, but not gotten round to doing is setting mstest.exe as the command line for the debug session, and seeing if that would work. But As I say, I’ve not tried it yet – if It works, please share 🙂


 


UPDATE: Sorry, I should have made it clearer, this is a Tip for the May CTP - we're intending on adding full support for debugging tests, it's just it's not in there right now.

Comments (3)
  1. Ian Cooper says:

    This works as a strategy when using nunit to run tests – just set the executable to either nunit-gui.exe or nunit-console.exe. We use that technique to launch a debugging session for our unit tests all the time here. So I would be hoping this would work with mstest.exe.

    While I’m here – the Visual Studio Team page doesn’t seem to link to the unit test support from the developer’s section. Might be good as, certainly most places I have been, developers tend to be the ones writing the unit tests, testers the application tests.

  2. Chris Garty says:

    Hi Dominic,

    Could you explain how to run the WebTest class via an exe?

    What does the main method do to kick off the running of the WebTests?

  3. UGbLog di Pierre Greborio says:

Comments are closed.

Skip to main content