android - searchManager.getSearchableInfo(getComponentName()) returns null only in test -
i have activity searchview under test, works expected tests fail.
@override protected void setup() throws exception { super.setup(); intent intent = new intent(getinstrumentation().getcontext(),startactivity.class); startactivity(intent, null, null); } @smalltest public void testshouldcreatestartactivity() { assertnotnull(activity); }
the test fails because of searchmanager.getsearchableinfo(activity.getcomponentname()) returning null.
searchmanager searchmanager = (searchmanager) activity.getsystemservice(context.search_service); searchableinfo searchableinfo = searchmanager.getsearchableinfo(activity.getcomponentname());
very frustrating have working app code tests fail.
i changed test class activityunittestcase activityinstrumentationtestcase2 , works.
read more differences here :
difference between activityunittestcase , activityinstrumentationtestcase2
Comments
Post a Comment