2012-05-30 39 views
1

我试图推动我的测试在活动间通信中,并检查例如正确登录后,我产生了正确的活动(来自2个可能的活动)。robolectric测试中的链接活动

这里是我的代码如下所示:

@RunWith(GuiceRobolectricJUnitRunner.class) 
public class LoginActivityTest { 
@Inject 
private LoginActivity activity; 
@Inject 
private ExplorerActivity startedActivity ; 
@Inject 
private Context context; 

private Button loginButton; 
private EditText login; 
private EditText password; 

@Before 
public void setUp() throws Exception { 
    activity.onCreate(null); 
    loginButton = (Button) activity.findViewById(R.id.identification_login_button); 
    login = (EditText) activity.findViewById(R.id.txtLogin); 
    password = (EditText) activity.findViewById(R.id.txtPassword); 

} 

@Online 
@Test 
public void shouldExploreWhenLoginIsCorrect() throws Exception { 
    assertNotNull(activity); 
    login.setText("[email protected]"); 
    password.setText("test"); 
    activity.setIntent(new Intent()); 
    loginButton.performClick(); 
    ShadowActivity shadowActivity = Robolectric.shadowOf(activity); 
    Intent startedIntent = shadowActivity.getNextStartedActivity(); 
    ShadowIntent shadowIntent = Robolectric.shadowOf(startedIntent); 
    assertEquals(shadowIntent.getIntentClass(), ExplorerActivity.class); 
//  startedActivity.setIntent(startedIntent); 
//  startedActivity.onCreate(null); 


    } 
} 

我的问题是,我不能检索从shadowintent的启动活动。有什么办法可以达到这样的效果吗?此外,我没有看到我的探索活动的任何迹象,我想知道Robolectric是否正在为每个产卵过程进行沙箱工作。我真的很喜欢robolectric中链式活动测试的例子。谢谢。

回答

4

从3个月前开始,您可能已经找到了答案,如果没有,您可以使用newInstance()来处理您已有的答案,然后按正常方式继续。

ExplorerActivity explorerActivity = (ExplorerActivity) shadowIntent.getIntentClass().newInstance(); 
explorerActivity.setIntent(startedIntent); 
explorerActivity.onCreate(null); 
相关问题