【发布时间】:2019-11-07 13:37:24
【问题描述】:
我正在尝试模拟 Calendar.getInstance() 以进行单元测试。
因此,我正在使用 PowerMock (powermock-core:2.0.4 & powermock-module-junit4:2.0.4) 及其 Mockito API (powermock-api-mockito2:2.0.4)。
我很清楚类似的情况doexist,但我面临一个似乎没有出现在其他情况下的异常。
确实,在做的时候
mockStatic(Calendar.class);
when(Calendar.getInstance()).thenReturn(aCalendar);
在用
注释的类中的测试方法上@RunWith(PowerMockRunner.class)
@PrepareForTest({DateUtils.class})
我收到以下错误:org.mockito.exceptions.misusing.NotAMockException: Argument should be a mock, but is: class java.lang.Class。
我做错了什么以及如何解决?
谢谢
【问题讨论】:
标签: java android unit-testing powermockito