簡體   English   中英

使用 Test Kit 測試自定義 Gradle 插件

[英]Testing custom Gradle plugin with Test Kit

我正在嘗試使用Test Kit測試自定義 Gradle 插件。

執行測試時,Gradle 無法找到被測插件

group 'com.example'
gradlePlugin {
    plugins {
        simplePlugin {
            id = 'example'
            implementationClass = 'com.example.ExamplePlugin'
        }
    }
}
@Test
public void test() throws IOException {
    writeFile(settingsFile, "rootProject.name = 'hello-world'");
    writeFile(buildFile, "plugins { id 'com.example.example' }");

    BuildResult result = GradleRunner.create()
            .withProjectDir(testProjectDir.getRoot())
            .withArguments("exampleTask")
            .build();

    assertThat(result.getOutput()).contains("Hello World!");

    assertThat(result.task(":exampleTask"))
            .isNotNull()
            .hasFieldOrPropertyWithValue("outcome", TaskOutcome.SUCCESS);
}
* What went wrong:
Plugin [id: 'com.example.example'] was not found in any of the following sources:

我使用 Gradle 6.5 將一個帶有最小失敗示例的存儲庫放在一起。 測試工具包文檔告訴我“Java Gradle 插件開發插件”將提供與測試工具包的直接集成,但我得到的錯誤表明被測試的插件在類路徑上不可用。

我試圖找到另一個正在使用 Test Kit 進行測試的有效示例插件,但沒有任何東西讓我感到意外。

事實證明我的代碼中有幾個問題

  1. 我缺少.withPluginClasspath()GradleRunner
  2. TestKit 不需要組前綴, plugins { id 'example' }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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