Unit Test File Structure

Ruby supports (and encourages) putting multiple class definitons in a file, I experimented with putting the Test-Class in the same file as the Class-under-Test. I found this useful, as

Has anyone else already tried this? Is there a trap before me that I do not see, yet? --DierkKoenig

You will always have the tests together with the code, which could have its downsides. The source files will also be bigger and thus harder to navigate. That's about it.

I usually find it quicker to switch between two files than to move around in one file, but that depends on the editor you are using.

Thanks. I also recognized that the tests automatically get executed when the class was loaded. Up to now I like that, but it may hurt me later. Anyway, I will experiment with this a little longer...

My experience with RubyUnit has been that it's easier to include the test class with the class, but then sometimes you create circular dependencies that are easiest to break by moving them into separate files. -- francis

I HaveThisPattern in Java. I wrote up a little UnitTest framework after reading ExtremeProgrammingExplained and putting the test class in the same file as the class seemed like the simplest thing to do. --ChristianTaubman


CategoryTesting


EditText of this page (last edited January 5, 2005) or FindPage with title or text search