Doing Test Driven Development with no DLLs

Doing test driven development often(well, practically always) entails testing against a class library in your tests. It's just the easiest way to test functionality of objects (you need to reference those objects somehow, right?) so, most of the time you would create a test project and a tested library project before you ever create a GUI or a console application that uses that library.
But what happens when you have a very small project? say, a very simple console application with a very small set of functionality? Well, in the TDD manner you would have the console app built along with a library project that contains the classes that do the functionality. But it may seem a bit like overkill to have 3 separate projects for a such a simple task. Or maybe the customer will not want to distribute the console app along with a dll for something so simple as say... renaming files in the directory based on some simple business logic. Maybet he requirement is that the user should only have to copy one exe file into the directory and run it with no hassles.
 
So.After all this text, what do you do when you can't use a library project for a very simple functionality?
 
You don't create a library project. Instead you create the necessary class(es) in your console app.
Then you link to those class files from your test project:
 
“MyTestProject->Add existing files->select the class file-> open the small menu on the “open” button and choose “link”.
 
Now you have a physical reference to the classes but you actually have only one instance of the class files for you to work with. This is as good as it gets for very small projects with a harsh requirement of “no DLLs please”. Use it wisely, grasshopper.
Published Friday, February 06, 2004 4:06 PM by RoyOsherove
Filed under:

Comments

Friday, February 06, 2004 10:29 AM by Lorenzo Barbieri

# re: Doing Test Driven Development with no DLLs

Very useful tip, thanks!!!
Friday, February 06, 2004 12:18 PM by Patrick Cauldwell

# re: Doing Test Driven Development with no DLLs

What I've had pretty good luck with is just including all my test (NUnit) classes in the assembly that I'm testing, without a separate project. I put them all in a subdirectory called "test", then in the formal build, I just don't include the contents of the "test" directory in the build for a release build.
Unfortunately, there's no good way to do that inside VS.NET, since I haven't been able to find any way to include different sets of files per build configuration.
But if you're using an external build tool like NAnt, it saves a lot of hassle creating extra projects, and you don't have to worry so much about references in you test classes.
Friday, February 06, 2004 3:23 PM by Udi Dahan - The Software Simplist

# re: Doing Test Driven Development with no DLLs

Patrick,

When putting the tests in the same assembly as the "unit" that your testing is risky. You are no longer treating it as a black box. This may start affecting the design of your tests.

All in all, I'd say not to put the tests in the same assembly as the code under test, unless you have an incontravertible reason to do so.
Monday, June 21, 2004 5:09 AM by TrackBack

# TDD / nUnit Links

Tuesday, August 17, 2004 2:51 PM by TrackBack

# TDD / nUnit Links