Grails 3:集成测试在开发环境中运行,而不是在测试环境中运行

时间:2016-03-22 09:44:37

标签: 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配置文件有测试部分。

有谁知道如何解决这个问题? 下面的命令没有帮助。

grails test test-app -integration 

1 个答案:

答案 0 :(得分:7)

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

相关问题