Juanma asked me a question about testing exe files, such as WinForms or Console apps, in response to my post How do you setup NUnit tests in Visual Studio.NET projects? The problem is you cannot add a reference to an executable assembly.
One easy trick is to change the project output type to Class Library. To do this, open the properties for the WinForm or Console project, and in the dropdown for Output Type, select Class Library. If you add a WinForm project, you will get an error message. To fix it, simple add a reference to the System.Windows.Forms assembly in the unit test project.
Then you can add a reference to your WinForm project and test any public methods just like a dll. When you change the Output Type back to Windows Application and rebuild, you’ll get the “cannot reference an exe” error message again. You can dereference the windows application again, but it’s easier to not build the unit tests project. Go to the Tools - Configuration Manager menu and deselect the unit test project(s). Then the unit tests will not be built, and you won’t get the error.
Alternatively, you can separate out all your business logic into a separate project that is a class library and not have any of these problems. However, this is not always feasible, and the trick above works well enough.
UPDATE: Jeff Key says to move just the Main method into a separate WinForms project, and then convert your original project into a Class Library. Then you won't have any conversion issues!
Posted
03-04-2004 11:17 AM
by
Darrell Norton