我升级了一个grails应用程序从1.2.2升级到1.3.7后,一些集成测试开始抛出以下错误'validateAndSaveList'是我正在测试的服务所使用的服务的方法。这些测试在升级之前通过,如果我只使用grails test-app -integration运行集成测试阶段,它们也会通过
junit.framework.AssertionFailedError: 不再调用'validateAndSaveList' 预计在这一点上。结束 需求。
代码:
import com.e.domain.*
import com.e.exception.GORMServiceException
import com.e.controller.SecurityUserCommand
class AccountServiceTests extends GroovyTestCase
{
def accountService
void testRegisterWithMinimumInfo()
{
def clinic = new Clinic(name:'clinicName')
def securityUserCommand = new SecurityUserCommand(username:'username', password:"password", confirm:"password")
def clinicUser = new ClinicUser(firstName:'fname', lastName:'lname', emailAddress:'abc@abc.com')
clinicUser.clinic = clinic
//clinicUser.securityUser = securityUser
clinic.address = new Address()
// TODO - JsecUser no longer in use
def role = new ShiroRole(name:'TEST')
//def subscription = ESubscription.findByName('Charter Member')
def subscription = new ESubscription(
name:'Charter Member',
description:'Charter Member',
periodType:'Monthly',
numPeriods:12,
amountPerPeriod:25.00,
electronicSubmissionRate:0.00,
accountingRate:0.01,
numAllowedUsers:4,
startDate: today -1,
endDate: today+1
)
subscription.save(flush:true)
if(subscription.hasErrors())
println subscription.errors
assertNotNull subscription
clinicUser.empathicCustomerProfile.subscription = subscription
def result = accountService.register(clinic, securityUserCommand, clinicUser, role)
assert result.success
assert result.clinic.id
assert result.securityUser?.id
assert result.clinicUser.id
}
栈跟踪
junit.framework.AssertionFailedError: No more calls to 'validateAndSaveList' expected at this point. End of demands.
at grails.test.MockClosureProxy.doBeforeCall(MockClosureProxy.java:66)
at grails.test.AbstractClosureProxy.call(AbstractClosureProxy.java:74)
at grails.test.GrailsMock$_createMock_closure1.doCall(GrailsMock.groovy:125)
at com.e.service.AccountService.register(AccountService.groovy:46)
at com.e.service.AccountService$register.call(Unknown Source)
at AccountServiceTests.testRegisterWithMinimumInfo(AccountServiceTests.groovy:53)
答案 0 :(得分:1)
这个答案来自于在评论中解决问题:
您得到的异常清楚地表明您已经在服务中放置了一个模拟对象,并且该服务正在以未设置处理的方式调用模拟对象。
答案 1 :(得分:1)
从@hvgotcodes看到的根问题是服务有一个模拟对象,即使在给定的测试中没有发生嘲弄。
这发生在grails 1.3.7
我找到了一个正在执行以下操作的单元测试:
def dataBindServiceControl = mockFor(DataBindService)
dataBindServiceControl.demand.safeBind{}
dataBindServiceControl.demand.extractPhones{}
dataBindServiceControl.demand.validateAndSaveList{l-> return true}
def dataBindService = dataBindServiceControl.createMock()
controller.dataBindService = dataBindService
如果删除了这些测试,那么所有的集成测试都会通过,以便解决重写测试时我将以下内容添加到拆卸方法中。
GroovySystem.metaClassRegistry.removeMetaClass(DataBindService)
通过此添加,测试现在可以在grails 1.3.7中正常运行