【发布时间】:2016-07-09 03:14:24
【问题描述】:
我已经分离了dataSourceConfig.yml数据库配置文件:
environments:
development:
dataSource:
dbCreate: none
url: jdbc:oracle:thin:xxxxxx
driverClassName: oracle.jdbc.OracleDriver
dialect: org.hibernate.dialect.Oracle10gDialect
username: xxxx
password: xxxx
test:
dataSource:
dbCreate: none
url: jdbc:oracle:thin:xxxxx
driverClassName: oracle.jdbc.OracleDriver
dialect: org.hibernate.dialect.Oracle10gDialect
username: xxxxx
password: xxxxx
我在Application.java中连接到项目:
class Application extends GrailsAutoConfiguration implements EnvironmentAware {
static void main(String[] args) {
GrailsApp.run(Application, args)
}
@Override
void setEnvironment(Environment environment) {
String configPath = environment.getProperty("local.config.location")
Resource resourceConfig = new FileSystemResource(configPath)
YamlPropertiesFactoryBean ypfb = new YamlPropertiesFactoryBean()
ypfb.setResources([resourceConfig] as Resource[])
ypfb.afterPropertiesSet()
Properties properties = ypfb.getObject()
environment.propertySources.addFirst(new PropertiesPropertySource("local.config.location", properties))
}
}
当我通过 Intellij IDEA 15 运行集成测试时,它会在 development 环境中运行测试,但 YAML 配置文件有 test 部分。
有谁知道如何解决这个问题? 下面的命令没有帮助。
grails test test-app -integration
【问题讨论】:
-
如果你运行
grails -Dgrails.env=test test-app -clean -integration会发生什么? -
@saw303 使用
grails或gradle运行测试时,您不需要指定-Dgrails.env=test。只有在使用 IDE 的内置运行配置内容从 IDE 运行时才需要这样做。 -
grails test test-app -integration无效。你可能想要grails test-app integration:或./gradlew iT。 -
@JeffScottBrown "要运行集成测试,您将运行... grails test-app -integration " 来自Grails 3.1.4 docs
标签: grails grails-3.1