Come testare le unità Android SensorEvent
e le classi MotionEvent
?Come simulare MotionEvent e SensorEvent per il test delle unità in Android?
Devo creare un oggetto MotionEvent
per il test dell'unità. (Abbiamo obtain
metodo per MotionEvent
che possiamo usare dopo beffardo per creare l'oggetto MotionEvent
personalizzato)
Per la classe MotionEvent, ho provato con Mockito
come:
MotionEvent Motionevent = Mockito.mock(MotionEvent.class);
Ma seguente errore sto ottenendo su 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)
a seguito del sito citato su questo errore, ho aggiunto
testOptions {
unitTests.returnDefaultValues = true
}
su build.gradle, ma continuo a ricevere lo stesso errore. Qualche idea su questo?
Per SensorEvent, un esempio: https://medium.com/@jasonhite/testing-on-android-sensor-events-5757bd61e9b0#.nx5mgk6sq – Kikiwa