I have searched over the Internet. However, I could not find any match answer to my case.
I use xml button to proceed the function.
android:onClick="hitSelectAnswer"
Here is my function in my Activity.
public boolean localStartActivityForResult(Intent intent, int requestCode){
startActivityForResult(intent, requestCode);
return true;
}
public void hitSelectAnswer(View view){
//...do something
intent = this.getNewIntent(SelectAnswer.class);
localStartActivityForResult(intent, 25811);
}
I use Mockito 1.10
I stub that function since it return true.
when(exerciseActivity.localStartActivityForResult(any(Intent.class), eq(25811))).thenReturn(true);
Call that function :
exerciseActivity.hitSelectAnswer(view);
Error :
Method startActivityForResult in android.app.Activity not mocked.
Question:
How do you test hitSelectAnswer() function?
My opinion:
I am refactoring the logic out from hitSelectAnswer.
Let doSomething() is a dedicated function for one job and test it. If you know the better way please let me know.
Aucun commentaire:
Enregistrer un commentaire