The Dopefly Tech Blog

<< The Dopefly Tech Blog Main page

How do you organize your unit tests

posted under category: ColdFusion on May 18, 2015 at 2:32 pm by MrNate

In my rush to make unit tests on my work primary development application, I've been putting unit test files all over the place. I don't think this is necessarily bad, as I've been telling myself it's better to have unit tests in the first place. Certainly unorganized unit tests is better than no unit tests whatsoever. I have a somewhat organized unit test runner, and my tests all fall into a larger test suite that provides the illusion of organization, yet still the files themselves are not organized.

So what is the best method? Unit test files in the same package (CF term for a folder) as the files they are testing? Tests in a central location? Mixed in with the model? Outside of the application you publish?

My current mode of thinking is to pull them out into a separate project, sort of a "project-contrib" project, for things like documentation and unit tests that I need, but don't want to deliver to the production web server. What do you think? What's worked for you?


Post A Comment!
On May 18, 2015 at 11:50 PM Dan Skaggs (dan.skaggs at the ever popular said:
We have both CFML and AngularJS projects that include unit tests. In both cases, we've put them into a folder at the project root (which is one level above the public web root). They get published with our CI server to all dev/stage environments but not to production. The build jobs that create the artifacts that the deploy jobs use to update the production servers are configured to not include the /tests directory.

As for organization, we like to have the subdirectory structure inside the /tests folder mirror that of the objects we're testing. So if we have /com/companyName/moduleName/service.cfc we'll have /tests/com/companyName/moduleName/serviceTest.cfc That has worked well for us to easily be able to determine where the test for a specific component is just by knowing the path to the component under test. The same organization has been applied to our Jasmine tests in our AngularJS apps.

On May 19, 2015 at 2:32 AM Adam Cameron ( said:
I'm similar to Dan in this regard, except our source code dir structure starts with /src in our project directory, and our test file structure mirror /src except are homed in /test.


On May 19, 2015 at 5:27 AM Julian Halliwell (julian, who eats said:
Still working out how best to organise my tests, but currently I have them close to the components they apply to. I'm finding it easier to work on both sets of code without having to open files in two different locations and keep the structure mirrored.

I don't put the tests in the same folder though as that would double the number of files to scan, making things harder to find. Instead the tests go in a /_test sub-folder. The underscore forces it to the top to make it easier to find. It's also easy to prevent anything in a /_test folder being deployed.

On May 19, 2015 at 10:29 AM Tom Mollerus (tom, by way of said:
We also store tests in a /test folder at the same level as /src. We also map the exact same folder structure that's in the /src/ folder, except right under /test we organize our files into the type of test we have (eg, /test/junit, /test/cfunit, /test/mxunit, etc).
Post A Comment!