【问题标题】:Grails 3: Integration tests run at a development environment, not at a test environmentGrails 3:集成测试在开发环境中运行,而不是在测试环境中
【发布时间】: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 使用grailsgradle 运行测试时,您不需要指定-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


【解决方案1】:

如果您要从 IDE 运行测试,您需要修改运行配置以包含 -Dgrails.env=test。您将希望对默认的 JUnit 运行配置执行此操作,这样您就不必编辑每个测试运行配置。请注意,编辑默认 JUnit 运行配置将影响将来创建的所有配置,但不会更新任何现有配置。您可能希望删除所有现有的运行配置,以便下次运行这些测试时使用新设置重新创建它们。

【讨论】:

  • 我说的是 IDE 中的运行配置,而不是您在 Grails 配置文件中指定的任何内容。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-04-05
  • 1970-01-01
  • 1970-01-01
  • 2022-11-10
  • 2021-06-12
  • 2014-10-16
相关资源
最近更新 更多