Unit Testing and Subversion - Where should I put the test classes?

I'm starting a strong push to institute Unit Testing in a relatively new project; I figure it will be easier to really get into the habits in a new project from the start, rather than trying to steer some of our ancient existing projects in that direction right away. But I've hit a snag... where should I keep the test classes?

We've been using Subversion to manage our project files since shortly after I started here... getting us into source control was one of my first imperatives. So our code is laid out nicely in folders:


Project A
|____ src
|____ lib
|____ docs
|____ db

Project B
|____ src
|____ lib
|____ docs
|____ db

In the src folder, I have things organized in packages like


src/edu.psu.ist.project-a.component-a
src/edu.psu.ist.project-a.component-b

So where do I put the test cases? I could put them in a test package at the root of the project:


src/edu.psu.ist.project-a.test.component-a
src/edu.psu.ist.project-a.test.component-b

But what I'm really leaning toward is mirroring the main folder structure of the package in a test package in the root of the repository, at the same level as the src folder:


src/edu.psu.ist.project-a.component-a
src/edu.psu.ist.project-a.component-b
test/testComponent-a
test/testComponent-b

My thinking is that the classes in the test package would not get deployed with my actual project code, so they shouldn't be in the real source package tree. But I'm still not sure.

Comments
Jeff Chastain's Gravatar At Alagad, we typically will mirror the source folder structure for our tests. This keeps the tests out of the source folder structure for easier deployment, but keeps them organized so that you can easily tell which test goes with which piece of code.

So, in your example, "src/edu.psu.ist.project-a.component-b" would have its tests in "test/edu.psu.ist.project-a.component-b".
# Posted By Jeff Chastain | 11/19/07 1:56 PM
Brian Kotek's Gravatar I go the other way and keep my tests with the components (or in a subdirectory), and just have ANT omit them (by wildcard) when it performs the deployment.
# Posted By Brian Kotek | 11/19/07 2:53 PM
Nat Papovich's Gravatar I've always put them in the same folder as the component, so for a file named MyComponent.cfc, I'd have a TestMyComponent.cfc in the same folder. I think it encourages keeping them up-to-date. I've recently been working on a project that uses Brian's StubGenerator and it puts test files in a "test" subfolder of each source folder, which is fine too. I still vote for having them right inside the source folders though. As others said, use a build script (I use some batch and vbs files instead of dealing with the lead weight of Ant) to get rid of these folders.
# Posted By Nat Papovich | 11/19/07 3:05 PM
Steven's Gravatar This is not really a subversion issue, rather an organizational issue. I would go with the way Ruby on Rails does it and put your unit tests inside a folder called test on the same level as your src, lib, docs, etc.

Unit tests are not supposed to test special "test" versions of your classes. They're supposed to test your real production classes, the classes you build your application with, the classes you deliver in your package. The classes you write for testing aren't compiled with the rest of your application because they're never imported.

You might also want to check out ASUnit: http://www.asunit.org/
# Posted By Steven | 11/19/07 4:46 PM
Brian Panulla's Gravatar Thanks for the helpful comments, everyone... it definitely seems like it's just a preference issue - there's More Than One Way To Do It. I think I'm learning towards Jeff's and Steven's suggestions of a test folder at the outermost level -- seems cleaner without having to do any filtering when building the deployment.

This is actually a Java project (well, the server side part is), but I left that out of the post since it really doesn't matter. I had the same quandry with both CFCUnit and ASUnit. It's definitely an organization thing... I want to put assets somewhere that they make sense, and stick to that convention.
# Posted By Brian Panulla | 11/19/07 5:11 PM
Sean Corfield's Gravatar I go with Jeff and Steven: I create a tests directory tree which mirrors the structure of my main components tree.
# Posted By Sean Corfield | 11/19/07 7:19 PM
BlogCFC was created by Raymond Camden. This blog is running version 5.9.1. Contact Blog Owner