测试类在依赖模块中扩展测试类 [英] Test class extending test class in dependency module

查看:174
本文介绍了测试类在依赖模块中扩展测试类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个模块中有一个测试类,它在一个依赖模块中扩展了另一个测试类。如何将依赖项的测试代码导入依赖模块的测试范围?

I've got a test class in a module that extends another test class in one of its dependency modules. How can I import the dependency's test code into the test scope of the dependent module?

为了文盲,我有两个模块,module-one是一个依赖项模块二。 SubTestCase TestCase的子类

To illiterate, I've got two modules, "module-one" being a dependency of "module-two". SubTestCase is a subclass of TestCase.


module-one
          \src\test\java\com\example\TestCase.java
module-two
          \src\test\java\com\example\SubTestCase.java

但构建失败,因为测试代码为module-one没有被导入模块二,只是主要代码。

But the build is failing because the test code of "module-one" is not being imported into "module-two", just the main code.

推荐答案

通常,除了常规的modulename.jar文件外,还可以通过构建和部署modulename-test.jar文件来解决这个问题。您可以像常规工件一样将这些部署到repos。这并不是完全无瑕疵,但对于代码工件来说效果不错。

Usually this is solved by building and deploying modulename-test.jar files in addition to the regular modulename.jar file. You deploy these to repos like regular artifacts. This is not totally flawless, but works decently for code artifacts.

然后,您可以将测试范围的依赖项添加到其他模块的test-jar中。

Then you would add test scoped dependencies to the test-jars to other modules.

您也可以通过将测试范围工件放在main范围内的独立模块中来解决这个问题,然后将其包含在其他模块的常规测试范围中。这个解决方案在多模块构建中不能很好地工作,其中每个模块导出一些测试工件,因为你基本上得到2N模块。

You can also solve this by putting test scoped artifacts in "main" scope in a separate module of its own and then include this in regular test-scope in other modules. This solution does not work very well in a multi-module build where each module exports some test artifacts, since you basically get 2N modules.

我们很多人实际上放弃了当我们意识到类的数量相当有限并且存在与这两种解决方案相关的问题时,在这两种解决方案上。我们只是将它们放在主要范围内的适当命名的包中。我只是忘记了为什么这两个第一个解决方案都很痛苦。

A lot of us actually give up on both of these solution when we realize that the number of classes is fairly limited and there are problems associated with both of these solution. We just put them in an appropriately named package in "main" scope. I just keep forgetting why the two first solutions are a pain.

这篇关于测试类在依赖模块中扩展测试类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆