没有 @RunWith(PowerMockRunner.class) 的模拟静态

gst*_*low 5 java junit mocking mockito powermock

我有以下代码:

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

如何替换此代码以使其无需使用@RunWith(PowerMockRunner.class)

根据以下链接中描述的原因,我无法使用@RunWith(PowerMockRunner.class)

Ale*_*exR 2

看看这个讨论:issues while using @RunWith Annotation and powerMock

答案之一建议使用PowerMockRule而不是跑步者。这个解决方案应该对你有好处。