How to unit test android SensorEvent and MotionEvent classes?
I need to create one MotionEvent object for unit testing. (We have a obtain method for MotionEvent , which we can use after bullying to create a MotionEvent object)
For the MotionEvent class, I tried using Mockito like:
MotionEvent Motionevent = Mockito.mock(MotionEvent.class);
But after the error, I get Android Studio:
java.lang.RuntimeException: Method obtain in android.view.MotionEvent not mocked. See https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support for details. at android.view.MotionEvent.obtain(MotionEvent.java)
After the site mentioned in this error, I added
testOptions { unitTests.returnDefaultValues = true }
on build.gradle, but still I get the same error. Any idea on this?
android mockito android-sensors android-testing
codevscolor
source share