简体   繁体   English

你如何组织单元测试包?

[英]How do you organize unit tests into packages?

As a matter of fact you have smth like /java/src and /java/test . 事实上,你有像/java/src/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? 当重构到来时,你手动重命名/ 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. 有一段时间有一些IDE有能力自动进行这种重构,但我不记得它在我的脑海中。

In Java, keeping them in the same package as the class being tested, is a must. 在Java中,将它们保存在与被测试的类相同的包中是必须的。 It's the only way to test methods with default/package-protected visibility. 这是使用默认/包保护可见性测试方法的唯一方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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