我有一个arraylist,并希望对一个将arraylist传递给另一个活动的意图编写一个Espresso UI测试。测试的整个想法是确认intent是否正确启动了调用活动
arraylist方法是
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;
}
虽然意图是
@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);
}
它实际上在传递数据的情况下正确启动了测验活动,浮动操作按钮实际上触发了使用@ + id / fab从主活动到测验活动的意图。我想写一个简单的espresso UI测试来验证按钮的成功点击并启动QuizActivity并传递数据