2017-08-11 1 views
0

wie Unit-Test-Preform diese FunktionUnit-Tests 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] 


    } 

Antwort

1

ich empfehlen würde nur zu testen, alle erforderlichen Service-Methode Anrufungen, spottet mit - nicht die Ergebnisse dieser Aufruf, sonst wird Ihr Test hängt davon ab, diese Methode. Diese Service-Methoden sollten ihre eigenen Tests haben.

Darüber hinaus testen, ob die view korrekt ist oder nicht, und model hat alle erforderlichen Eigenschaften.

Siehe, Grails - Unit Testing Controllers.

Docs, wird Ihnen helfen, aktuelle view und model zu bekommen.

Befehl, grails create-unit-test, grails create-unit-test <your-controller-here>, generiert die Testklasse für Sie zu beginnen.