我正在从在线教程中学习,并尝试通过自己的方式实现一些功能.当检测到长按列表项时,如何弹出一个对话框来提醒用户?以下是该教程的一些代码:
public class FriendList extends ListActivity
{
private static final int ADD_NEW_FRIEND_ID = Menu.FIRST;
private static final int EXIT_APP_ID = Menu.FIRST + 1;
private IAppManager imService = null;
private FriendListAdapter friendAdapter;
public String ownusername = new String();
private class FriendListAdapter extends BaseAdapter
{
class ViewHolder {
TextView text;
ImageView icon;
}
private LayoutInflater mInflater;
private Bitmap mOnlineIcon;
private Bitmap mOfflineIcon;
private FriendInfo[] friends = null;
public FriendListAdapter(Context context) { // Constructor of Class "FriendListAdapter"
super();
mInflater = LayoutInflater.from(context);
mOnlineIcon = …Run Code Online (Sandbox Code Playgroud) 我试图在选择列表项和下一个活动的意图上编写一个junit测试用例,但是我不知道如何通过junit编码来模拟此用户操作。有人可以帮忙吗?
我也想问,是否有任何材料可以在junit中模拟不同的用户操作来教授其功能或语法?
以下是我的学校教程笔记中的一个示例,我想做一个类似的事情,但要在listview项上做。
public void testKilosToPounds() {
/* INTERACTIONS */
TouchUtils.tapView(this, textKilos); // tap the EditText textKilos
sendKeys("1"); // sent the number 1
TouchUtils.clickView(this, buttonPounds); // click the button buttonPounds
/*CHECK THE RESULT*/
double pounds;
try {
pounds = Double.parseDouble(textPounds.getText().toString());
} catch (NumberFormatException e) {
pounds = -1;
}
//JUnit Assert equals
// message expected actual delta for comparing doubles
assertEquals("1 kilo is 2.20462262 pounds", 2.20462262, pounds, DELTA);
}
Run Code Online (Sandbox Code Playgroud)