【发布时间】: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)只包含一个测试的信息。
有没有办法使用不同的系统属性运行不同的测试?
【问题讨论】: