jeudi 1 octobre 2015

Mocking in Android

I'm attempting to test the isKeyguardSecure() method of the KeyguardManager class in an Android application.

I've tried and failed using EasyMock, Mockito, and PowerMock to create a mock KeyguardManager object. Below are my attempts and the error messages received.


EasyMock

KeyguardManager keyguardManagerMock = EasyMock.createMock(KeyguardManager.class);

Error message: java.lang.IllegalArgumentException: android.app.KeyguardManager is not an interface


Mockito and PowerMock

KeyguardManager mockedKeyguardManager = Mockito.mock(KeyguardManager.class); KeyguardManager mockedKeyguardManager = PowerMockito.mock(KeyguardManager.class);

Error messages: java.lang.VerifyError: mockit/internal/startup/Startup java.lang.VerifyError: org/mockito/cglib/core/ReflectUtils


One explanation for this states that the root problem is with the Dalvik virtual machine that Android devices run. Can anyone verify this? Is it possible to mock the KeyguardManager class using any available mocking library that will work in testing an Android app?

Thanks!

Aucun commentaire:

Enregistrer un commentaire