I'm trying to test two different Activity
classes, where one Activity
happens to call the other. Here's my code and then I'll 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
is non-null, it immediately starts RootActivity
. If it's null, it stays on IntroActivity
. The problem is that if it is non-null, the 1st test (IntroActivityTest
) passes, and then it hangs on the getActivity()
method call in RootActivityTest
and the test just freezes...no exceptions, it just hangs on that line. If the user token is null, it runs both tests completely fine.
What could be causing this? From observation, it appears that RootActivityTest
is trying to use the RootActivity
that was started from IntroActivity
, but shouldn't it be starting its own instance of RootActivity
?