Grails 3 : Integration tests run at a development environment, 不在测试环境中

标签 grails grails-3.1

我已经分离了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/

相关文章:

grails - 将静态资源(css、js、htm)添加到 grails 3 应用程序

grails - Grails 3:运行集成测试后出现IllegalStateException

java - Gradle 可以解决依赖关系并正常构建/运行,但 IntelliJ 不能

grails - 移植到grails 3时将MappingFactory转换为ToMany的ClassCastException

Grails 对象引用未保存的 transient 实例

grails - 在Groovy/Grails中使用XmlSlurper解析Pingdom XML响应

grails - 测试 View 时如何模拟Asset-Pipeline taglib

grails - gradle测试未运行Geb测试

html - 如何在 Grails g :selects? 中实现虚拟值

grails - Grails GORM:映射树旧表