Android测试用例活动测试

时间:2013-06-15 09:33:22

标签: android java-ee android-testing

我现在有一个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);
    }       
}

1 个答案:

答案 0 :(得分:0)

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

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