How to android unit test and mock a static method
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试): 问题: Hi I really hope you can help me, I feel like I've been pulling my hair out for days. I'm trying to write unit tests for a method A. Method A calls a static method B. I want to mock static method B. I know this has been asked before, but I feel Android has matured since then, and there must be a way to do such a simple task without re-writing the methods I want to test. Here is an example, first the method I want to test: public String getUserName(Context context, HelperUtils helper) { if(helper == null){ helper = new HelperUtils(); } int