Android: UnitTest -


need advice. have app. , need write unittest. don't know test. test settings , preferences, that's easy. else people test ? lets have 3 activities. main 1 list activity, when click on list item forward on second list activity...and on list item click forward on third activity. think maybe should test switching between activities ? how simulate click on list item in unittest , how check activity open or not ? !

android provides test classes able exhaustive in unit testing want be. can unit test java components, android-architecture dependant components, , workflow whole.

in case, test sequences between activities, can use instrumentationtestcase class , extend it, , in tests, should use following methods:

// prepare monitor activity instrumentation instrumentation = getinstrumentation() instrumentation.activitymonitor monitor = instrumentation.addmonitor(yourclass.class.getname(), null, false);  // start activity manually intent intent = new intent(intent.action_main); intent.setflags(intent.flag_activity_new_task); intent.setclassname(instrumentation.gettargetcontext(), yourclass.class.getname());         instrumentation.startactivitysync(intent);  // started activity activity currentactivity = getinstrumentation().waitformonitor(monitor); 

then can remove monitor , add monitor next activity expect catch in workflow sequence. sequence can programatically interact , verify sequences of actions go through multiple activities.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -