使用powermockito.mockstatic时@preparefortest要使用哪个类?

ctzwtxfj  于 2021-07-06  发布在  Java
关注(0)|答案(0)|浏览(276)

我有如下代码。我想写一个测试方法的测试。但是,methoda调用属于类“b”的静态methodb。
我的问题是,在尝试使用“powermockito.mockstatic”时,需要为测试准备哪个类?
它是
什么?或
b呢?或
是吗?或
以上的一些组合?

  1. class A {
  2. public methodA() {
  3. String response = B.methodB(params);
  4. }
  5. }
  1. import org.junit.Test;
  2. import org.junit.runner.RunWith;
  3. import org.powermock.modules.junit4.PowerMockRunner;
  4. import org.powermock.core.classloader.annotations.PrepareForTest;
  5. @RunWith(PowerMockRunner.class)
  6. @PrepareForTest({ ... })
  7. class ATest {
  8. @Test
  9. public testMethodA() {
  10. A instance = new A();
  11. PowerMockito.mockStatic(B.class);
  12. String someString = "dummy response!";
  13. PowerMockito.when(B.methodB(anyString())).thenReturn(someString);
  14. instance.methodA();
  15. }
  16. }

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题