【问题标题】:How to write Test for sourceSets block in Gradle plugin如何在 Gradle 插件中为 sourceSets 块编写测试
【发布时间】:2020-04-01 07:16:38
【问题描述】:

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

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

【问题讨论】:

    标签: java gradle groovy gradle-plugin


    【解决方案1】:

    找到了一种方法来编写这个场景的测试,把你的资源放在 一些名为 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"))
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-04-25
      • 1970-01-01
      • 2021-11-14
      • 1970-01-01
      • 2015-03-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多