views:

172

answers:

3

I have a project group with the main project and a test project.

When writing unit tests for a class in the main project, do you include the source file in the test project, or do you put the path to it in the search path?

Why do you do one over the other?

Are there any best practices on this?

UPDATE: It looks like including is the preferred option, much because of the disadvantages of 'getting access' to all units in the search path vs only getting access to the units that you intend to use. What bugs me, though, is the need to include a file in two projects all the time. I usually keep the test project as the active project, so when I need a new class, I create a new unit, that becomes a part of the test project, but store it under the main projects path. Now, I need to remember to also include it in the main project. There should be a 'create new unit, and add it to all open projects'-action....

+1  A: 

If the source files have important initialization or finalization sections then it may be necessary to include them in the testing project, otherwise it is not.

In latter case do not extend the unit test project's search path too much though, rather use one output directory for dcus of the main project.

Ozan
+4  A: 

I include the source as it seems to make the IDE happier WRT speed, Code Completion, etc.

Craig Stuntz
+5  A: 

You should probably include the units in the test project rather than rely on a search path. You will have a much better understanding of the dependencies between units, and should make any additional dependencies obvious should they occur (particularly if they are undesirable). It might also be desirable to have more than one test project if you want to make sure there is no cross dependencies between certain parts of you main application (for example if you have some shared code with another application)

Alister
Actually, including them makes it much easier to navigate across sources in Delphi as well. Shortcuts like Ctrl-F12, Shift-F12 now show your tested code too.--jeroen
Jeroen Pluimers