我在集成测试中遇到了一个问题。我的代码使用系统属性 (System.getProperty(...) ),运行集成测试时我无法设置系统属性。关于如何定义在集成测试中运行的代码中可见的系统属性的任何想法?
我正在使用 Grails 3.3.1。精简的集成测试示例没有看到系统属性:
package injecttest
import grails.testing.mixin.integration.Integration
import grails.transaction.*
import org.springframework.beans.factory.annotation.Autowired
import spock.lang.Specification
@Integration
@Rollback
class C1ITSpec extends Specification {
void "test system property readable inside test"() {
String val = System.getProperty("var1", "ERROR")
expect:"system variable to match value passed as '-Dvar1=OK' in command line"
"OK" == val
}
}