How do you organize unit tests into packages?
-
10-07-2019 - |
Question
As a matter of fact you have smth like /java/src
and /java/test
. But then, how do you name packages/classes the unittests go to? The same as classes they are written against? And when refactoring comes, do you manually rename in /test? Please share your experience.
Solution
I keep the tests in the same package as the class they are testing. This allows me to setup tests using package private members (when required). It also provides a nice, easy to remember convention. When I refactor, I usually do manually refactor the corresponding test classes. There was some IDE a while back that had the ability to do this refactoring automatically, but I can't remember it off the top of my head.
OTHER TIPS
In Java, keeping them in the same package as the class being tested, is a must. It's the only way to test methods with default/package-protected visibility.