如何在 Gradle 插件中编写 sourceSets 块测试

How to write Test for sourceSets block in Gradle plugin

最近,我正在做一个使用许多 gradle groovy 插件的项目,我引入了一个块,在 sourceSets 中添加一些静态文件。现在如何为 sourceSets 块编写测试? 我在 sourceSets 中添加的块是

 project.sourceSets {
            test {
                resources {
                    srcDir project.files("${project.projectDir}/some-folder")
                }
            }
        }

找到一种方法来编写这个场景的测试,把你的资源放在 一些名为 tempFile 的文件夹是用于测试的资源。同样的测试:TestPluginSpec.groovy

 @Rule
    TemporaryFolder testProjectDir = new TemporaryFolder()
    File tempFile
    tempFile = testProjectDir.newFile('tempFile')
    buildFile = testProjectDir.newFile('build.gradle')

    buildFile << """
             plugins {
                id 'java'
               }
   """
def "should add test Resources into build/resources/test"(){
        when:
        def result = GradleRunner.create().withProjectDir(testProjectDir.root).withPluginClasspath().withArguments('processTestResources').withDebug(true).build()
        then:
        result.task(":processTestResources").outcome == TaskOutcome.SUCCESS
        and:
        Files.exists(Paths.get("${testProjectDir.root.path}/build/resources/test/tempFile"))
    }