mock static without @RunWith(PowerMockRunner.class)

微笑、不失礼 提交于 2019-12-23 12:53:09

问题


I have folowing code:

        @RunWith(PowerMockRunner.class)
        @PrepareForTest({RequestUtils.class, OsgiUtil.class})
        @PowerMockIgnore({"*"})
        public class MyTest
            ...
             @Test
             public somMethod(){    
                ....  
                mockStatic(RequestUtils.class);
                when(RequestUtils.getLocale(request)).thenReturn(locale);
            }
        }  

How to replace this code so that it work without @RunWith(PowerMockRunner.class)?

According the cause described in following link I cannot use @RunWith(PowerMockRunner.class)


回答1:


Take a look on this discussion: issues while using @RunWith Annotation and powerMock

One of the answers recommends to use PowerMockRule instead of runner. This solution should be good for you.



来源:https://stackoverflow.com/questions/24141580/mock-static-without-runwithpowermockrunner-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!