[英]Unit testing Grails controller
how to preform unit test this function 如何执行此功能的单元测试
private void secondaryRepError(def secRepCmd) {
def repProfile = springSecurityService?.currentUser?.representativeProfile
def productTypes = representativeManagementService.getAssignedProductTypes(repProfile)
def facilities = representativeManagementService.getAssignedFacilities(repProfile)
def facilityType = representativeManagementService.getFacilityType()
def listOfRetail = representativeManagementService.listOfFacilities(facilities?.toList(), facilityType?.retail)
def listOfLpg = representativeManagementService.listOfFacilities(facilities?.toList(), facilityType?.lpg)
def listOfPipeline = representativeManagementService.listOfFacilities(facilities?.toList(), facilityType?.pipeline)
def listOfRelated = representativeManagementService.listOfFacilities(facilities?.toList(), facilityType?.related)
render view:'addSecondaryRep', model: [secondaryRepInstance: secRepCmd, appType: ApplicationType.getAll(), productTypes: productTypes, facilities: facilities, retailFacility: facilityType?.retail, lpgFacility: facilityType?.lpg, pipelineFacility: facilityType?.pipeline, facFacility: facilityType?.related, listOfRetail: listOfRetail, listOfLpg: listOfLpg, listOfPipeline: listOfPipeline, listOfRelated:listOfRelated]
}
I would recommend to just test all the required service method invocations, using mocks -- not the results of those invocation, otherwise your test depends on those method. 我建议仅使用模拟测试所有必需的服务方法调用-而不是这些调用的结果,否则您的测试将取决于这些方法。 Those service methods should have their own tests. 这些服务方法应具有自己的测试。
Moreover, test whether the view
is correct or not, and model
has all the required properties. 此外,测试view
是否正确,并且model
具有所有必需的属性。
Refer, Grails - Unit Testing Controllers . 请参阅Grails-单元测试控制器 。
Docs , will help you in getting current view
and model
. 文档 ,将帮助您获取当前view
和model
。
Command, grails create-unit-test , grails create-unit-test <your-controller-here>
, will generate the test class for you to start with. 命令, grails create-unit-test , grails create-unit-test <your-controller-here>
,将为您生成测试类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.