0

I have an activity with a searchview which is under test, Everything works as expected but the 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 to have working app code but the tests fail.

Decoy
  • 1,598
  • 12
  • 19

1 Answers1

0

I changed the test class from ActivityUnitTestCase to ActivityInstrumentationTestCase2 and now it works.

read more about the differences here :

Difference between ActivityUnitTestCase and ActivityInstrumentationTestCase2

Community
  • 1
  • 1
Decoy
  • 1,598
  • 12
  • 19