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.
The easiest way to organize your tests is to place them directly alongside your production code, in the same package and source tree. If you do this, all the code you need to compile is in one directory structure, simplifying your build process.
If your package and test code are small and self contained, put the tests in with the package. If the tests are large or complex, or require reading/writing files, or significant sample data, put your tests outside the package.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With