【问题标题】:Gradle: different system properties for different testsGradle:不同测试的不同系统属性
【发布时间】:2013-10-31 11:49:24
【问题描述】:

我为 Spock 写了一个扩展。 @Configuration 有两个参数:环境和文件 - 配置文件的路径,解析 groovy.util.ConfigSlurper。此外,可以将参数指定为系统属性:“org.wsw.spock.cfg.file”、“org.wsw.spock.cfg.environment”。如果指定了系统属性,它们会覆盖注释中指定的设置(不确定是否更好,但仍然如此)。

我编写了两个不同规格的测试。在 gradle 中运行它们是这样写的:

task configTest ( type: Test, dependsOn: testClasses) {
    include '**/ConfigurationTest.class'
}

task configSysPropsTest ( type: Test, dependsOn: testClasses) {

    include '**/ConfigurationTestSysProps.class'

    systemProperty 'org.wsw.spock.cfg.file', 'feature_test.gconfig'
    systemProperty 'org.wsw.spock.cfg.environment', 'dev'
}

task test( overwrite: true,
    dependsOn: [ configTest, configSysPropsTest ])

它可以工作,但是覆盖任务测试,在我看来不是很好。报告文件夹(build/reports/tests)只包含一个测试的信息。

有没有办法使用不同的系统属性运行不同的测试?

【问题讨论】:

    标签: gradle spock


    【解决方案1】:

    我不太明白您为什么要覆盖 test 任务。无论如何,运行具有不同系统属性的不同测试的唯一方法是拥有多个Test 任务。在这种情况下,您需要显式配置 Test.reportsDir(或更新的 Gradle 版本中的 Test.reports.html.destination)。

    也许你可以改变你的插件,让每个测试类都有自己的系统属性。然后您可以一次设置所有系统属性。

    【讨论】:

      【解决方案2】:

      您不能在测试类的setup() 方法中为每个测试添加不同的gradle.properties 吗?

      例如:

      • 测试1FileUtils.copyFile(new File(loader.getResource('test1.properties').getPath()), new File("${testProjectDir.root.absolutePath}/gradle.properties"))

      • Test2FileUtils.copyFile(new File(loader.getResource('test2.properties').getPath()), new File("${testProjectDir.root.absolutePath}/gradle.properties"))

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2017-12-10
        • 1970-01-01
        • 2017-09-24
        • 1970-01-01
        • 2016-12-17
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多