I'm testing my app with Robolectric, but whenever there is an asynctask
the execution flow continue without waiting for it, after some research I found this method flushBackgroundThreadScheduler()
that execute all runnables that have been queued on the background scheduler, but I get the same results and onDone
method is never called.
Am I using the right method? How to fix this?
EDIT
this my code setUp method + test method :
@Before
public void setUp() throws Exception {
activity = Robolectric.setupActivity(SignUpActivity.class);
}
@Test
public void startNewActivityWhenLoginSuccess() throws Exception {
// Arrange
String email = "aersdfsqdz@z.zz";
String password = "zzzzzz";
Class clazz = NameActivity.class;
Intent expectedIntent = new Intent(activity,clazz);
// Act
activity.register_email.setText(email);
activity.register_password.setText(password);
activity.fragment1.button.callOnClick();
Robolectric.flushBackgroundThreadScheduler(); //from 3.0
//ShadowLooper.runUiThreadTasksIncludingDelayedTasks();
// Assert
ShadowActivity shadowActivity = Shadows.shadowOf(activity);
Intent actualIntent = shadowActivity.getNextStartedActivity();
assertTrue(expectedIntent.filterEquals(actualIntent));
}