2

问题:是否可以运行位于一个 Gradle 项目中的 JUnit 测试,并且依赖于另一个项目?

背景

考虑这个多项目设置:

product_1_configuration_with_tests/
feature_a_with_tests/
feature_b_with_tests/
common_integration_tests/
  • 为简单起见,产品项目依赖于其他三个项目。不存在其他依赖项。
  • common_integration_tests包含所有产品通用的集成测试,必须在产品的上下文(类路径/依赖项)中运行。
  • common_integration_tests不能对任何其他项目有任何依赖关系。
  • 常见集成测试的行为因运行时类路径上的内容而异。

如何运行这种常见的集成测试?

尝试

理想情况下,我希望在产品项目中定义测试任务。我尝试在套件中包含集成测试:

// In product_1_configuration_with_tests/build.gradle
task integrationTest(type: Test) {
  include '**/MyIntegrationTest.class'
}

由于测试任务没有找到驻留在另一个模块中的测试,因此不执行任何测试。

4

1 回答 1

0

要么将集成测试源声明为项目的单独源集product_1_configuration_with_tests(放弃common_integration_tests项目),要么声明来自common_integration_testson的依赖项product_1_configuration_with_tests。在新建项目中,前者是更可取的方法,但后者也可以。其他解决方案不必要地复杂。

common_integration_tests 不能对任何其他项目有任何依赖关系。

为什么?

于 2013-03-25T14:25:02.083 回答