最近,我正在一个使用许多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"))
}
关于java - 如何在Gradle插件中编写Test for SourceSets block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60965460/