I have an arraylist and would like to write an Espresso UI test on an intent that passes the arraylist to another activity, The whole idea of the test is to confirm if the intent launches the calling activity correctly
The arraylist method is
public List<Insect> insectList(){
insects = new ArrayList<>();
singleInsect = new Insect();
if (cursor.getCount() > 0){
int count = 0;
while (cursor.moveToNext()){
if (count < quizActivity.ANSWER_COUNT){
count++;
insect = new Insect(cursor.getString(cursor.getColumnIndex(BugsContract.BugsEntry.COLUMN_FRIENDLYNAME)),
cursor.getString(cursor.getColumnIndex(BugsContract.BugsEntry.COLUMN_SCIENTIFICNAME)),
cursor.getString(cursor.getColumnIndex(BugsContract.BugsEntry.COLUMN_CLASSIFICATION)),
cursor.getString(cursor.getColumnIndex(BugsContract.BugsEntry.COLUMN_IMAGEASSET)),
Integer.parseInt(cursor.getString(cursor.getColumnIndex(BugsContract.BugsEntry.COLUMN_DANGERLEVEL)))
);
insects.add(insect);
}
}
Collections.shuffle(insects);
singleInsect = insects.get(3);
}
Collections.shuffle(insects);
return insects;
}
While the intent is
@Override
public void onClick(View v) {
//TODO: Launch the quiz activity
Intent intent = new Intent(this, QuizActivity.class);
intent.putStringArrayListExtra(quizActivity.EXTRA_INSECTS, (ArrayList) insects);
intent.putExtra(quizActivity.EXTRA_ANSWER, singleInsect);
this.startActivity(intent);
}
It actually launched the Quiz Activity correctly with data passed, floating action button actually triggers the intent from Main Activity to Quiz Activity with @+id/fab. I would like to write a simple espresso UI test to verify the successful click of the button and launches the QuizActivity with data also passed
Aucun commentaire:
Enregistrer un commentaire