到目前为止,我已经尝试了所有可用的建议。
问题:我正在尝试为基于 Grails 的应用程序编写集成测试用例,但是在运行测试时,它默认选择 H2 db 来创建数据源,而不是使用 application.yml 中的测试环境中的数据库配置
使用的命令: grails -Dgrails-env=test tesp-app -integration
版本: grails=4.0.1 gorm=7.0.2.RELEASE
应用程序.yml
---
grails:
profile: web
codegen:
defaultPackage: myApp
gorm:
autowire: true
reactor:
# Whether to translate GORM events into Reactor events
# Disabled by default for performance reasons
events: false
info:
app:
name: "my-grails-app"
version: "0.0.10"
grailsVersion: '4.0.1'
spring:
jmx:
unique-names: true
main:
banner-mode: "off"
groovy:
template:
check-template-location: false
devtools:
restart:
additional-exclude:
- '*.gsp'
- '**/*.gsp'
- '*.gson'
- '**/*.gson'
- 'logback.groovy'
- '*.properties'
management:
endpoints:
enabled-by-default: false
---
grails:
mime:
disable:
accept:
header:
userAgents:
- Gecko
- WebKit
- Presto
- Trident
types:
all: '*/*'
atom: application/atom+xml
css: text/css
csv: text/csv
form: application/x-www-form-urlencoded
html:
- text/html
- application/xhtml+xml
js: text/javascript
json:
- application/json
- text/json
multipartForm: multipart/form-data
pdf: application/pdf
rss: application/rss+xml
text: text/plain
hal:
- application/hal+json
- application/hal+xml
xml:
- text/xml
- application/xml
urlmapping:
cache:
maxsize: 1000
controllers:
defaultScope: singleton
converters:
encoding: UTF-8
views:
default:
codec: html
gsp:
encoding: UTF-8
htmlcodec: xml
codecs:
expression: html
scriptlet: html
taglib: none
staticparts: none
management:
endpoints:
jmx:
unique-names: true
---
hibernate:
cache:
queries: false
use_second_level_cache: false
use_query_cache: false
# cache.provider_class: 'org.hibernate.cache.EhCacheProvider'
lazy: false
max_fetch_depth: '5'
environments:
development:
datasource:
pooled: true
dbCreate: update
driverClassName: 'com.mysql.jdbc.Driver'
url: 'jdbc:mysql://127.0.0.1:3306/mysqlDB_dev?useLegacyDatetimeCode=false&serverTimezone=UTC'
username: 'root'
password: 'root'
logSql: true
validationQuery: "SELECT 1"
test:
datasource:
pooled: true
dbCreate: create-drop
driverClassName: 'com.mysql.jdbc.Driver'
url: 'jdbc:mysql://127.0.0.1:3306/mysqlDB_test?useLegacyDatetimeCode=false&serverTimezone=UTC'
username: 'root'
password: 'root'
logSql: true
production:
datasource:
pooled: true
dbCreate: update
driverClassName: 'com.mysql.jdbc.Driver'
url: 'jdbc:mysql://127.0.0.1:3306/mysqlDB_prod?useLegacyDatetimeCode=false&serverTimezone=UTC'
username: 'xxxxx'
password: 'xxxxx'
logSql: true
validationQuery: "SELECT 1"
properties:
jmxEnabled: true
initialSize: 5
maxActive: 50
minIdle: 5
maxIdle: 25
maxWait: 10000
maxAge: 600000
timeBetweenEvictionRunsMillis: 5000
minEvictableIdleTimeMillis: 60000
validationQuery: SELECT 1
validationQueryTimeout: 3
validationInterval: 15000
testOnBorrow: true
testWhileIdle: true
testOnReturn: false
jdbcInterceptors: ConnectionState
defaultTransactionIsolation: 2 # TRANSACTION_READ_COMMITTED