我已经分居dataSourceConfig.yml
数据库配置文件:Grails的3:集成测试在开发环境中运行,而不是在一个测试环境
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运行集成测试时,它在开发环境下运行测试,但YAML配置文件有测试部分。
有谁知道如何解决这个问题? 命令波纹管没有帮助。
grails test test-app -integration
如果你运行'grails -Dgrails.env = test test-app -clean -integration',会发生什么? – saw303
@ saw303使用'grails'或'gradle'运行测试时,您不需要指定'-Dgrails.env = test'。这应该只在使用IDE的内置运行配置文件从IDE运行时才需要。 –
'grails test test-app -integration'无效。您可能需要'grails test-app integration:'或'./gradlew iT'。 –