gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-01 04:47:20 24 4
gpt4 key购买 nike

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

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

最佳答案

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

common_integration_tests can not have any dependencies to any other projects.

为什么?

关于java - 使用 Gradle 从另一个项目运行 JUnit 测试?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15613177/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com