使用Gradle从另一个项目运行JUnit测试?

时间:2013-03-25 10:54:56

标签: java junit gradle

问题:是否可以运行位于一个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'
}

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

1 个答案:

答案 0 :(得分:0)

要么将集成测试源声明为product_1_configuration_with_tests项目的单独源集(放弃common_integration_tests项目),要么声明common_integration_testsproduct_1_configuration_with_tests的依赖关系。 1}}。在绿地项目中,前者是更好的方法,但后者也可以。其他解决方案不必要地复杂化。

  

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

为什么?

相关问题