I am trying to test two different Activity classes, where one Activity calls another one. Here is my code, and then I will explain the problem:
IntroActivityTest
public class IntroActivityTest extends ActivityInstrumentationTestCase2<IntroActivity> { IntroActivity activity; public IntroActivityTest() { super( IntroActivity.class ); } @Override protected void setUp() throws Exception { super.setUp(); activity = getActivity(); } public void testIntroBypass() { if ( new SharedPreferencesHelper( getInstrumentation().getTargetContext() ).retrieveUserToken() == null ) { assertTrue( !activity.isFinishing() ); } else { assertTrue( activity.isFinishing() ); } } }
RootActivityTest:
public class RootActivityTest extends ActivityInstrumentationTestCase2<RootActivity> { RootActivity activity; public RootActivityTest() { super( RootActivity.class ); } @Override protected void setUp() throws Exception { super.setUp(); activity = getActivity(); } public void testInitialTab() { assertTrue( activity.getSupportActionBar().getSelectedTab().getText().toString().equalsIgnoreCase( "Library" ) ); } }
In IntroActivityTest , if the user token from SharedPreferences not null, it immediately starts RootActivity . If it is zero, it stays on IntroActivity . The problem is that if it is not equal to zero, the first test passes ( IntroActivityTest ), and then it hangs when the getActivity() method is getActivity() in RootActivityTest , and the test just hangs ... no exceptions, it just hangs on this line. If the user token is zero, it performs both tests perfectly.
What could be the reason for this? From the observation, it seems that RootActivityTest trying to use RootActivity , which was launched from IntroActivity , but should it not run its own instance of RootActivity ?
source share