Grails 3:在开发环境而不是测试环境中进行集成测试 运行
Grails 3: Integration tests run at a development environment, not at a test environment
我已经分离了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 配置文件有 测试节。
有人知道如何解决这个问题吗?
下面的命令没有帮助。
grails test test-app -integration
如果您要从 IDE 进行 运行 测试,您需要修改 运行 配置以包含 -Dgrails.env=test
。您将希望为默认的 JUnit 运行 配置执行此操作,因此您不必编辑每个测试 运行 配置。请注意,编辑默认的 JUnit 运行 配置将影响将来创建的所有配置,但不会更新任何现有配置。您可能想要删除所有现有的 运行 配置,以便在您下次 运行 这些测试时使用新设置重新创建它们。
我已经分离了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 配置文件有 测试节。
有人知道如何解决这个问题吗? 下面的命令没有帮助。
grails test test-app -integration
如果您要从 IDE 进行 运行 测试,您需要修改 运行 配置以包含 -Dgrails.env=test
。您将希望为默认的 JUnit 运行 配置执行此操作,因此您不必编辑每个测试 运行 配置。请注意,编辑默认的 JUnit 运行 配置将影响将来创建的所有配置,但不会更新任何现有配置。您可能想要删除所有现有的 运行 配置,以便在您下次 运行 这些测试时使用新设置重新创建它们。