Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Grails 3: Integration tests run at a development environment, not at a test environment

I have separated dataSourceConfig.yml database config file:

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

Which I connect to the project in the 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))
    }
 }

When i run integration tests via Intellij IDEA 15, it runs tests at a development environment, but the YAML config file has test section.

Is anyone knows how to fix this? The command bellow doesn't help.

grails test test-app -integration 
like image 887
Sergey Linnik Avatar asked Mar 22 '16 09:03

Sergey Linnik


1 Answers

If you are going to run tests from the IDE you need to modify the run config to include -Dgrails.env=test. You will want to do that for the default JUnit run config so you don't have to edit every single test run config. Be aware that editing the default JUnit run config will affect all configs that are created in the future but will not update any existing configs. You may want to remove all of the existing run configs so they will be recreated with the new settings the next time you run those tests.

like image 170
Jeff Scott Brown Avatar answered Nov 08 '22 18:11

Jeff Scott Brown