集成测试在grails升级时开始失败 [英] Integration Tests started to fail with grails upgrade
问题描述
我升级了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扩展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不再使用
def role = new ShiroRole(name:'TEST')
// def subscription = ESubscription.findByName('Charter Member')
def subscriptio n =新的ESubscription(
名称:'Charter Member',
描述:'Charter Member',
periodType:'每月',
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订阅
clinicUser.empathicCustomerProfile.subscription =订阅
def result = accountService.register(clinic,securityUserCommand,clinicUser,role)
assert result.success
assert result.clinic.id
assert result.securityUser?.id
assert result.clinicUser.id
}
StackTrace
junit.framework.AssertionFailedError:没有更多调用'validateA ndSaveList'在这一点上预计。要求结束。
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)
这个答案来自于在评论中解决问题:
你正在清楚的异常清楚地表明你在你的服务中放置了一个模拟对象,该服务正在以未设置处理的方式调用模拟对象。
I upgraded a grails app from 1.2.2 to 1.3.7 after this upgrade a few integration tests have started to throw the following error the 'validateAndSaveList' is a method on a service used by the service I'm testing. These tests were passing before the upgrade and they will also pass if I run just the integration test phase with grails test-app -integration
junit.framework.AssertionFailedError: No more calls to 'validateAndSaveList' expected at this point. End of demands.
Code:
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
}
StackTrace
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)
this answer comes from working the issue out in the comments:
the exception you are getting clearly indicates that somewhere you have put a mock object in your service, and the service is calling the mock object in a way it was not set up to handle.
这篇关于集成测试在grails升级时开始失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!