How can I use PrivateObject to access private members of both my class and its parent?

前端 未结 7 1915
逝去的感伤
逝去的感伤 2020-12-08 07:41

I\'m testing a class that is part of a hierarchy. I\'ve been setting up my test classes with the object under test, and a PrivateObject to allow access to that

相关标签:
7条回答
  • 2020-12-08 08:36
    // create an instance of class SearchPlanogramsBuilder:
    SearchPlanogramsBuilder searchPlanogramBuilder = new SearchPlanogramsBuilder(); 
    
    // executing the method BuildSearchParameters(return type is void) with input searchPlanoGramsFilters:
    searchPlanogramBuilder.BuildSearchParameters(searchPlanoGramsFilters);
    
    // create privateobject and pass instance created for the class:
    PrivateObject helperobject1 = new PrivateObject(searchPlanogramBuilder);
    
    // type cast exactly as parameter(which is private variable) in the method:
    Collection<string> parameter = (Collection<string>)helperobject1.GetFieldOrProperty("parameters");
    
    0 讨论(0)
提交回复
热议问题