如何使 maven 测试依赖于另一个项目测试中定义的类? [英] How can I make a maven test dependent on a class defined in another project's test?

查看:51
本文介绍了如何使 maven 测试依赖于另一个项目测试中定义的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个项目,A 和 B.项目 A 依赖于项目 B.项目 B 实现了几个 JUnit 测试,这些测试与 maven 测试一起正常运行.项目 B JUnit 测试还定义了项目 A 和 B 都依赖的一些常量.当我在项目 B 上运行 maven install 时,没有任何测试类(即常量)进入项目 B SNAPSHOT jar,因此当项目 A 查找项目 B 的常量时,它在已安装的项目 B 的 SNAPSHOT jar 中找不到它们在我的本地仓库中.有什么方法可以告诉 maven 打包/安装测试 SNAPSHOT jar 或类似的东西,以便项目 A 在测试期间可以访问这些常量?这些常量仅用于测试.

I have two projects, A, and B. Project A depends on project B. Project B implements several JUnit tests that run properly with maven test. Project B JUnit tests also define some constants that both project A, and B rely on. When I run maven install on project B none of the test classes (namely the constants) make it into the Project B SNAPSHOT jar, so when project A looks for project B's constants it can't find them in project B's SNAPSHOT jar that is installed in my local repo. Is there any way to tell maven to package/install a test SNAPSHOT jar, or something similar so project A can have access to those constants during the test? These constants are only used in the tests.

推荐答案

  • 简单的解决方案:将常量放在 src/main/java 中,并明确它们仅用于测试代码.使用简短的包名称,例如 testing.
  • 过度设计的解决方案:将常量放在一个单独的 maven 项目中(可能只有 POM?),由 A 和 B 引用,范围为 test.
  • 这篇关于如何使 maven 测试依赖于另一个项目测试中定义的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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