我试图将一个Grails应用程序(版本2.2.2)部署到Jenkins(版本1.638)。它运行clean
,test-app -Dgrails.env=XXX
和war
命令。
clean
和war
效果很好。对于test-app -Dgrails.env=XXX
,单元测试部分工作正常,每个测试用例都通过了。但是,大多数集成测试用例都失败了似乎控制器中的域类无法获取数据。换句话说,get()
或list()
方法未返回正确的记录。我假设数据库连接正确,因为控制台输出没有抱怨连接问题。集成测试在具有相同数据源的本地计算机上运行良好。
测试错误类似于以下代码,size()
始终为0.这是一个控制器集成测试。 results
由控制器中域类的get()
,list()
或createCriteria().list{}
方法返回。
results.size() == 9
| | |
[] 0 false
以下是DataSource.groovy中的代码。我尝试了testCI
和testCI2
。这两种设置都没有帮助。老实说,我对pool properties
了解不多。我刚刚复制了它。
hibernate {
cache.use_second_level_cache = true
cache.use_query_cache = false
cache.region.factory_class = 'net.sf.ehcache.hibernate.EhCacheRegionFactory'
}
environments {
testCI {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://localhost:3306/build_db" // For non network testing
driverClassName = "com.mysql.jdbc.Driver"
username ="build"
password = "build"
pooled=true
properties {
maxActive = -1
minEvictableIdleTimeMillis=1800000
timeBetweenEvictionRunsMillis=1800000
numTestsPerEvictionRun=3
testOnBorrow=true
testWhileIdle=true
testOnReturn=true
validationQuery="SELECT 1"
}
}
}
testCI2 {
dataSource {
dbCreate = "update" // one of 'create', 'create-drop', 'update', 'validate', ''
url = "jdbc:mysql://localhost:3306/build_db" // For non network testing
driverClassName = "com.mysql.jdbc.Driver"
username ="build"
password = "build"
}
}
}
最奇怪的是,在我将新提交推送到git存储库之后,集成测试有时会运行良好。但事实并非如此。
有没有人有任何想法?非常感谢你!!
答案 0 :(得分:0)
对于集成测试,您需要一个真实的(来自您的示例,MySQL)数据库。
是否在Jenkins服务器上安装了MySQL - 在运行集成测试时,这是本地主机。