에서 "드롭을 만듭니다." 일부 테스트의 경우 통합 테스트를 위해 실제 데이터베이스가 필요합니다.Grails는 프로퍼티 파일을로드하고 사용할 때 dbCreate = 내가 환경 구성에 약간의 문제가있어 동시에
config-integration.properties :
# connection
db.name=integration_test
db.host=127.0.0.1
db.port=3306
dataSource.driverClassName=com.mysql.jdbc.Driver
dataSource.url=jdbc:mysql://${db.host}:${db.port}/${db.name}?useUnicode=yes&characterEncoding=UTF-8&autoReconnect=true
dataSource.dialect=org.hibernate.dialect.MySQL5InnoDBDialect
# configuration
dataSource.username=foo
dataSource.password=bar
dataSource.dbCreate=create-drop
dataSource.pooled=true
dataSource.properties.maxActive=50
dataSource.properties.maxIdle=25
dataSource.properties.minIdle=5
dataSource.properties.initialSize=5
dataSource.properties.minEvictableIdleTimeMillis=60000
dataSource.properties.timeBetweenEvictionRunsMillis=60000
dataSource.properties.maxWait=10000
dataSource.properties.validationQuery=/* ping */
Config.groovy 파일 : 우리가 테스트를 시작 깨끗한 데이터베이스 매번를 위해, 우리는 우리가 이미로드 된 구성 파일에 때 dbCreate 속성을 변경 생각
environment {
....
integration {
log4j = {
root { debug 'stdout' }
warn 'org.apache'
warn 'grails.spring'
info 'org.codehaus.groovy.grails'
warn 'net.sf.ehcache'
warn 'org.hibernate'
}
grails.serverURL = "http://www.foobar.com"
if (!grails.config.locations || !(grails.config.locations instanceof List)) {
grails.config.locations = []
}
// loading default configuration
grails.config.locations << "classpath:app/config-integration.properties"
grails.gorm.failOnError = true
}
....
}
문제 지금이 단순히 작동하지 않습니다. 테이블이 작성되지 않으므로 SQL 예외로 테스트가 종료됩니다. 잘못된 것으로 변경하면 잘못된 사용자 이름/비밀번호에 관한 메시지조차 없습니다. 그래서 grails/hibernate가 데이터베이스에 테이블을 생성해야하는 순간에 설정이로드되지 않은 것처럼 보입니다.
편집 : 나는 잊었다 무엇 : 내가 Config.groovy 파일 자체에 데이터 소스를 정의하는 경우, 그것은 작동합니다.
사람은 내가 잘못 여기서 뭘하는지 생각이 있습니까?
미리 감사드립니다.
config-integration이 클래스 경로에 있는지 확인하십시오. groovy로 변환하고 println을 사용하여 파일이로드되었는지 확인할 수도 있습니다. –
다른 환경 설정과 마찬가지로 grails-app/conf/app에 있으며, 환경에 관계없이 사용자 정의 환경에 상관없이 올바르게로드됩니다. create-drop 부분과 특정 링크가있는 것 같습니다. b/c 데이터베이스가 이미 설정되어있는 경우에도 작동합니다 (테스트의 옵션 b/c는 아닙니다). – Moritz