【发布时间】:2011-08-26 13:26:14
【问题描述】:
在此升级后,我将一个 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)
【问题讨论】:
-
请发布代码和堆栈跟踪。看起来你的模拟的期望失败了
-
已更新代码和堆栈跟踪
-
如果我将它作为 grails test-app AccountService 运行,测试也会通过,但当我作为 grails test-app 运行时不会通过
-
您在哪里设置 accountService.register 的期望值?
-
除了您在此处看到的内容和服务中的实际逻辑之外,什么都没有做。
标签: grails