我已经分离了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 运行集成测试时,它在开发环境中运行测试,但 YAML 配置文件有 test 部分。
有人知道如何解决这个问题吗? 下面的命令没有帮助。
grails test test-app -integration
最佳答案
如果您要从 IDE 运行测试,则需要修改运行配置以包含 -Dgrails.env=test
。您需要对默认的 JUnit 运行配置执行此操作,这样您就不必编辑每个测试运行配置。请注意,编辑默认的 JUnit 运行配置将影响将来创建的所有配置,但不会更新任何现有配置。您可能想要删除所有现有的运行配置,以便下次运行这些测试时使用新设置重新创建它们。
关于Grails 3 : Integration tests run at a development environment, 不在测试环境中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36150913/