本文介绍了没有@RunWith(PowerMockRunner.class)的模拟静态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下代码:
@RunWith(PowerMockRunner.class)
@PrepareForTest({RequestUtils.class, OsgiUtil.class})
@PowerMockIgnore({"*"})
public class MyTest
...
@Test
public somMethod(){
....
mockStatic(RequestUtils.class);
when(RequestUtils.getLocale(request)).thenReturn(locale);
}
}
如何替换此代码,使其在不使用@RunWith(PowerMockRunner.class)
的情况下工作?
How to replace this code so that it work without @RunWith(PowerMockRunner.class)
?
根据以下链接中所述的原因,我不能使用@RunWith(PowerMockRunner.class)
According the cause described in following link I cannot use @RunWith(PowerMockRunner.class)
推荐答案
看一下这个讨论:
答案之一是建议使用PowerMockRule
而不是跑步者.该解决方案应该对您有益.
One of the answers recommends to use PowerMockRule
instead of runner. This solution should be good for you.
这篇关于没有@RunWith(PowerMockRunner.class)的模拟静态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!