views:

115

answers:

2

When working with Visual Studio in general (or Visual C# Express in my particular case), it looks like each project can be configured to produce only one output - e.g. a single executable or a library.

I'm working on a project that consists of a shared library and a few application, and I already have one project in my solution for each of those. However, during development I find it useful to write small example programs that can run one small subsystem in isolation (at a level that doesn't belong in the unit tests).

Is there a good way to handle this in Visual Studio? I'd like to avoid adding several dozen separate projects to my solution for each small test program I write, especially when these programs will typically be less than 100 lines of code. I'm hoping to find something that lets me continue to work in Visual Studio and use its build system (rather than moving to something like NAnt).

I could foresee the answer being something like:

  • A way of setting this up in Visual Studio that I haven't found yet
  • A GUI like NUnit's graphical runner that searches an assembly for classes with defined Main() functions that you can select and run
  • A command line tool that lets you specify an assembly and a class with a Main function to run
+2  A: 

Rather than write small test programs, consider writing unit tests. That leads you directly in to Test Driven Development.

You can have as many unit tests in a test project as you need.

Eric J.
Exactly. I can't see any good reason why these individual programs can't simply be different test methods, unless you're polluting static mutable state all over the place.
kyoryu
I'm already using unit tests - the purpose of this is to do simple integration testing, and to check real-world behaviors (such as how network code reacts under various circumstances) so that they can be accurately mocked.
Kevin Ivarsen
@Kevin: You can still use unit testing infrastructure for this type of test. It fits much more naturally into the VS workflow than creating many small programs. You would want to assign such tests to a group that don't get routinely run when you unit test the application per se, or perhaps add them to a separate test project.
Eric J.
@Kevin: What is an executable but a program that calls a specific method (main) at a predetermined time? How is that different from what a unit testing framework does, except that the unit testing framework can call different methods instead of just main? I'd probably want a separate project for my integration tests, but I dont' see why a new project would be necessary for each one - again, unless you're relying on a bunch of static state that you really *need* to be cleared between runs.
kyoryu
A: 

One project - one output. Simple. No way around it.

Use unit tests for snippet compilation.

Sky Sanders