16

Is there even a standard convention for this? I see a lot of different and perhaps misguided package naming that is very mixed in some projects and thus is never consistent:

Let's say I want to write unit tests for something that falls under the 'stuff' package.

 com.company.product.amodule.submodule.stuff

The unit test could be one of these possibilities (or even somewhere between):

  • com.company.test.product.amodule.submodule.stuff
  • com.company.product.amodule.submodule.stuff.test
1

2 Answers 2

18

Have it inside the same namespace (package). I like maven convention to separate source folders

src root-folders:

  • production code: src/main/...
  • test code: src/test/...

You can map this to your own build-system

1
  • 1
    Is there an easy way to follow this convention in Eclipse without using maven? Jul 9, 2014 at 14:57
7

I tend to keep the tests in the same namespace/package as the code it's testing, but in a different project.

1
  • 7
    This is helpful partly because it allows the tests to access package-protected code. Sep 10, 2010 at 14:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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