0

我现在有一个使用 ListView 和 CustomCursorAdapter 的活动,我希望自动化测试。一切都很好,但是当适配器中没有记录时,屏幕上会显示一个警报对话框,现在问题是我无法访问活动测试(android 测试用例)的警报对话框并且无法处理警报对话框事件关于测试框架,先生,请在这方面帮助我。提前致谢。

对话框创建代码。

@Override
protected Dialog onCreateDialog(int id){

    String msg = null;
    switch(id){
    case CALL_SETTING:
        builder =  new AlertDialog.Builder(this);
        builder.setTitle("CIH - HELP");         
        msg = "Please Allow me to guide you Configure this fresh CIH-MA.";                  
        builder.setMessage(msg);
        builder.setCancelable(true);
        builder.setPositiveButton("OK", new settingOnClickListener());
        builder.setNegativeButton("Cancel", new cancelOnClickListener());
        alDialog = builder.create();
        alDialog.show();
        break;
    case CALL_SITE:
        builder =  new AlertDialog.Builder(this);
        builder.setTitle("CIH - HELP");
        msg = "Please press 'Site' button to Add new Site for Monitoring and Controling Device ";
        builder.setMessage(msg);
        builder.setCancelable(true);
        builder.setPositiveButton("OK", new siteOnClickListener());
        builder.setNegativeButton("Cancel", new cancelOnClickListener());
        alDialog = builder.create();
        alDialog.show();
        break;
    }
    return super.onCreateDialog(id);

}
private final class settingOnClickListener implements DialogInterface.OnClickListener{

    @Override
    public void onClick(DialogInterface dialog, int which) {
        // TODO Auto-generated method stub
        ZigbeeActivity.this.startActivity(new Intent(ZigbeeActivity.this,AboutScreen.class));           
    }       
}
private final class cancelOnClickListener implements DialogInterface.OnClickListener{
    @Override
    public void onClick(DialogInterface dialog, int which) {
        // TODO Auto-generated method stub

    }       
}
private final class siteOnClickListener implements DialogInterface.OnClickListener{

    @Override
    public void onClick(DialogInterface dialog, int which) {
        // TODO Auto-generated method stub
        Intent LocationIntent = new Intent(ZigbeeActivity.this,SelectLocation.class);
        LocationIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK|Intent.FLAG_ACTIVITY_CLEAR_TOP);
        ZigbeeActivity.this.startActivity(LocationIntent);
    }       
}
4

1 回答 1

0

通过一些重构,您可以使用BoundBox访问您的活动的私有状态。

例如,将所有代码放在监听器中的私有方法中,并使用模拟上下文测试它们以查看是否正确接收了意图。

于 2013-09-17T09:10:58.387 回答