0

我为 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)仅包含一项测试的信息。

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

4

2 回答 2

1

I don't quite understand why you are overwriting the test task. Anyway, the only way to run different tests with different system properties is to have multiple Test tasks. And in that case, you need to configure Test.reportsDir (or Test.reports.html.destination in more recent Gradle versions) explicitly.

Perhaps you could change your plugin so that each test class has its own system property. Then you can set all system properties at once.

于 2013-10-31T12:31:39.197 回答
0

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

例如:

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

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

于 2017-01-24T18:15:03.193 回答