mercredi 28 octobre 2015

Using of reflection in Android Istrumentation tests

I'm using ActivityInstrumentationTestCase2 for testing activities in android application and inside my tests I'm trying to assess private fields. But the matter is every time trying it via reflection as

Field f = activity.getClass().getDeclaredField("dateSelector"); 
f.setAccessible(true);
EditText iWantThis = (EditText) f.get(activity);

or (WebView) FieldUtils.readDeclaredField(activity, "currentWebView", true)

my tests stop, not fail and I get

Disconnected from the target VM, address: 'localhost:8605', transport: 'socket'

Thought the same code worked well in unit tests. Any ideas?





Aucun commentaire:

Enregistrer un commentaire