繁体   English   中英

单元测试Grails控制器

[英]Unit testing Grails controller

如何执行此功能的单元测试

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]


  }

我建议仅使用模拟测试所有必需的服务方法调用-而不是这些调用的结果,否则您的测试将取决于这些方法。 这些服务方法应具有自己的测试。

此外,测试view是否正确,并且model具有所有必需的属性。

请参阅Grails-单元测试控制器

文档 ,将帮助您获取当前viewmodel

命令, grails create-unit-testgrails create-unit-test <your-controller-here> ,将为您生成测试类。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM