mock中測試private方法,不是mock


Method method = PowerMockito.method(CategoryController.class, "getCategory",List.class);//創建調用CategoryController類中的getCategory私有方法的method對象,參數是list對象
List<Category> category_all_actual = (List<Category>)method.invoke(categoryController, categories);//調用categoryController的私有方法,返回list對象,參數是list對象
assertArrayEquals(category_all_expect.toArray(), category_all_actual.toArray());//比較實際返回的對象與期望的對象是否相等.

或者:// PowerMockito.doReturn(index_expect).when(controller, "processPage", pageCode, request, response, model); // Mock私有方法

或者:// PowerMockito.when(controller, "processPage", pageCode, request, response, model).thenReturn(index_expect); // Mock私有方法

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM