简体   繁体   中英

How do you organize unit tests into packages?

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.

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM