2016-03-22 106 views
5

我已经分居dataSourceConfig.yml数据库配置文件:Grails的3:集成测试在开发环境中运行,而不是在一个测试环境

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 
+0

如果你运行'grails -Dgrails.env = test test-app -clean -integration',会发生什么? – saw303

+1

@ saw303使用'grails'或'gradle'运行测试时,您不需要指定'-Dgrails.env = test'。这应该只在使用IDE的内置运行配置文件从IDE运行时才需要。 –

+0

'grails test test-app -integration'无效。您可能需要'grails test-app integration:'或'./gradlew iT'。 –

回答

7

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

+0

我正在讨论IDE中的运行配置,而不是您在Grails配置文件中指定的任何配置。 –

相关问题