我应该将共享测试实用程序放在多模块 Maven 项目中的哪里?
我可能不应该对此太着迷,但我的项目有一个我非常喜欢的非常结构化的布局。这次事实证明拥有这么多结构是有用的,所以我真的不希望它再次变得混乱。
首先,每个模块都由几个 Java 包组成:
com.mycompany.mysoftware.modulename
com.mycompany.mysoftware.modulename.impl
com.mycompany.mysoftware.modulename.osgi
com.mycompany.mysoftware.modulename.test
主要代码位于 .impl
中。其他模块使用的接口、一些枚举和一些数据容器类位于没有后缀的包中。 .osgi
包中包含 OSGi 特定代码(BundleActivator
等),而 .test
包中包含单元测试。
现在我有一些类可以伪造一个模块以用于测试其他模块。我想知道是否应该将它们放在已经包含主代码共享库的 common
模块的 .test
包中,或者我是否应该有一个新模块test
我可以在 Maven 中设置不同的依赖范围。
预计到达时间:我遇到的一个问题是循环依赖:如果我有两个模块,并且每个模块中的单元测试都需要另一个的假版本,则包含假版本的模块依赖于包含接口的模块,它与包含单元测试的模块相同。所以,假货应该和测试放在一起,但这会导致大量的代码重复。或者,对于每个模块,我都会制作一个假模块,但这让我觉得它已经失控了......
I probably sholdn't obsess about this too much, but my project has a very structured layout that I have become very fond of. Having that much structure has actually proven to be useful, this time, so I don't really want it to become messy again.
To start with, each module consists of several Java packages:
com.mycompany.mysoftware.modulename
com.mycompany.mysoftware.modulename.impl
com.mycompany.mysoftware.modulename.osgi
com.mycompany.mysoftware.modulename.test
The main code lives in .impl
. Interfaces, some enums and some data container classes that are used by other modules live in the package with no suffix. There's OSGi specific code (BundleActivator
s etc.) in the .osgi
package and unit tests in the .test
package.
Now I have classes that fake a module to be used in testing others. I'm wondering whether I should put those in the .test
package of a common
module that already contains shared libraries for the main code, or whether I should have a new module test
that I can set up a different dependency scope for in Maven.
ETA: One problem I'm having is that I get circular dependencies: if I have two modules and the unit tests in each require a fake of the other, the module containing the fake has a dependency on the module containing the interface, which is the same module that contains the unit test. So, the fake should be together with the test, but that leads to a lot of code duplication. Or, for each module I make a fake module, but that makes me feel it's getting out of hand...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不希望您的测试代码打包在主代码使用的公共模块中,是吗?
所以答案对我来说似乎很明显:创建一个测试模块并将其用作测试范围的依赖项。
(编辑:我正在回答下面问题更新中提到的问题)
关于循环依赖关系,将接口放在单独的模块中怎么样?
You don't want your testing code to be packaged in the common module used by main code, do you?
So the answer seems obvious to me: create a test module and use it as dependency with a test scope.
(EDIT: I'm putting an answer to the problem mentioned in the update of the question below)
Regarding the circular dependencies, what about putting the interfaces in a separated module?