0
Robotive로 테스트를 구현 중이며 정적 메소드가 호출되었는지 또는 호출되지 않았는지 확인해야하는 테스트를 구현하려고합니다. 내 테스트는 다음과 같습니다Robolectric 및 PowerMockito로 고정 메소드 모방
@RunWith(RobolectricTestRunner.class)
@Config(manifest=Config.NONE)
@PrepareForTest({DeviceUtils.class})
@SmallTest
public class ContactsListPresenterTest extends BasePresenterTest {
...
@Test
public void onCallContactClicked_nullArgument_methodNotCalled() {
PowerMockito.mockStatic(DeviceUtils.class);
presenter.onCallNotaryClicked(context, null);
PowerMockito.verifyStatic(Mockito.never());
DeviceUtils.dialPhoneNumber(context, Mockito.anyString());
}
@Test
public void onCallContactClicked_nullArgument_methodCalled() {
PowerMockito.mockStatic(DeviceUtils.class);
presenter.onCallNotaryClicked(context, new Contact());
PowerMockito.verifyStatic(Mockito.times(1));
DeviceUtils.dialPhoneNumber(context, Mockito.anyString());
}
}
테스트가 다음 오류와 함께 실패 그러나 : 내가 잘못
org.powermock.api.mockito.ClassNotPreparedException:
The class x.DeviceUtils not prepared for test.
To prepare this class, add class to the '@PrepareForTest' annotation.
In case if you don't use this annotation, add the annotation on class or method level.
을 뭐하는 거지? 이미 @PrepareForTest 주석을 추가 했으므로 PowerMockitoRunner 대신 RobolectricTestRunner를 사용하고 있기 때문에 이것이 모두라고 생각합니다. 그러나이 동일한 클래스의 다른 테스트에서는 RoboelectricTestRunner가 필요합니다.
덕분에 많은
@Rule 공용 PowerMockRule 규칙을 추가하면 새 PowerMockRule(); 클래스 내의 모든 테스트가 실패한다 : java.lang.RuntimeException : java.lang.ClassNotFoundException : org.powermock.classloading.DeepCloner – FVod