簡體   English   中英

使用Gradle從另一個項目運行JUnit測試?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM