![](/img/trans.png)
[英]gradle: How to run JUnit tests of a child project from the root project?
[英]Run JUnit tests from another project using 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'
}
由於測試任務找不到位於另一個模塊中的測試,因此不會執行任何測試。
您可以將集成測試源聲明為product_1_configuration_with_tests
項目的一個單獨的源集(放棄common_integration_tests
項目),或者聲明對product_1_configuration_with_tests
common_integration_tests
依賴性。 在新建項目中,前者將是首選方法,但后者也將起作用。 其他解決方案不必要地復雜。
common_integration_tests不能與任何其他項目有任何依賴關系。
為什么?
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.