Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've got a couple of data access objects (DefaultPersonServices.class, DefaultAddressServices.class) which is responsible for various CRUD operations in a database.

A few different classes use these services, but as the services requires that a connection is established with a database I can't really use them in unit tests as they take too long. Thus, I'd like to create a test doubles for them and simply do FakePersonServices.class and FakeAddressService.class implementations which I can use throughout testing.

Now, this is all good (I assume)...but my question relates to where I put the test doubles. Should I keep them along with the default implementations (aka "real" implementations) or should I keep them in a corresponding test package.

The default implementations are found in Source Packages : Should I keep the test doubles here too, or should the test doubles rather be in Test Packages :

share|improve this question
up vote 3 down vote accepted

Unless they will actually be used by something other than tests, then they belong in the test package.

Possibly you might want them to go into a separate "test objects" package if you're publishing your "source packages" and want other people to be able to write unit tests incorporating them, but unless you know this to be the case right now, I'd say YAGNI.

FWIW: There is only one instance in my past where I actually included fakes in the primary source code, and that was when the site was actually designed to be able to run in "demo mode" without an underlying database. As you can probably guess, these were true fakes, not just stubs or dummies, and the maintenance on them was considerable. Very few projects have any need for this, but I'm pointing it out anyway for the sake of completeness.

share|improve this answer
Thanks for that. I won't be needing the software to run in demo mode, and will simply just fake the methods which actually returns entities. The ones doing Create, Update and Delete operations will just be empty implementations. I'll be the only one using them, so I'll simply just put the in my test sources. Thanks! – sbrattla Oct 21 '13 at 6:56

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.