如何编写可扩展列表子视图的android junit测试用例?

时间:2014-01-02 09:13:18

标签: android-listview junit expandablelistview

我想为ExpandableListView子视图编写测试用例。 我有一组可扩展列表视图。每个小组都有独立的儿童布局。所以每次儿童计数都是1。 我想使用

为mAcTxtCarName设置AutoCompleteTextView的settext
TouchUtils.tapView(this, mAcTxtCarName);
sendKeys(KeyEvent.KEYCODE_H, KeyEvent.KEYCODE_U);

但我不能发送这样的钥匙。

这是我正在使用的代码。 在这段代码中,在assertSame(view,expandedView);找不到相同的。

public void testStartCheckListActivity() throws Exception {

        // add monitor to check for the second activity
        final ActivityMonitor monitor = getInstrumentation().addMonitor(
                CheckListActivity.class.getName(), null, false);

        // find button and click it
        final Button btnNewCalibration = (Button) mMenuActivity
                .findViewById(R.id.btn_new_calibration);

        // TouchUtils handles the sync with the main thread internally
        TouchUtils.clickView(this, btnNewCalibration);

        // wait 2 seconds for the start of the activity
        final CheckListActivity checkListActivity = (CheckListActivity) monitor
                .waitForActivityWithTimeout(2000);
        assertNotNull(checkListActivity);

        /** **New Calibration** */
        // add monitor to check for the second activity
        final ActivityMonitor monitorNewCalibration = getInstrumentation().addMonitor(
                NewCalibrationActivity.class.getName(), null, false);

        // find button and click it
        final Button btnCheckListNext = (Button) checkListActivity
                .findViewById(R.id.btn_footer_done);

        TouchUtils.clickView(this, btnCheckListNext);
    // wait 2 seconds for the start of the activity
        final NewCalibrationActivity newCalibrationActivity = (NewCalibrationActivity) monitorNewCalibration
                .waitForActivityWithTimeout(2000);
        assertNotNull(newCalibrationActivity);

        /** we get list view */
        final ExpandableListView expandableListView = (ExpandableListView) newCalibrationActivity
                .findViewById(R.id.explist_newcalibration);

        newCalibrationActivity.runOnUiThread(new Runnable() {

            @Override
            public void run() {
                expandableListView.requestFocus();
                expandableListView.performItemClick(expandableListView, 2,
                        expandableListView.getItemIdAtPosition(2));
            }
        });

        JunitUtils.waitTime(10);
        // *******get last calibration or validation details for default
        // display.**********
        final PreferencesStorage preferncesStorage = new PreferencesStorage();
        // New Calibration Details object from preference storage.
        final NewCalibrationDetails calibrationDetails = preferncesStorage
                .getNewCalibrationDetails(newCalibrationActivity);

        final SQLAdapter adapter = new SQLAdapter(newCalibrationActivity);
        adapter.open();
        adapter.getLastCalibrationDetails(calibrationDetails);
        adapter.close();
        // **************************************************************************

        if (expandableListView.isGroupExpanded(2)) {
            Logger.d(tag, "$$$$$$$$$$$$$$$$$$$$$$$$$$$");
            final LayoutInflater mLayoutInflater = (LayoutInflater) newCalibrationActivity
                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            final View view = mLayoutInflater.inflate(R.layout.items_newcalibration_child_3,
                    expandableListView, false);

            // final View view = View.inflate(newCalibrationActivity,
            // R.layout.items_newcalibration_child_3, null);

            AutoCompleteTextView mAcTxtCarName = (AutoCompleteTextView) view
                    .findViewById(R.id.actxt_car_name);
            AutoCompleteTextView mAcTxtModelNumber = (AutoCompleteTextView) view
                    .findViewById(R.id.actxt_model_number);
            EditText mEdTxtLicencePlate1 = (EditText) view.findViewById(R.id.et_licence_plate_1);
            EditText mEdTxtLicencePlate2 = (EditText) view.findViewById(R.id.et_licence_plate_2);
            EditText mEdTxtLicencePlate3 = (EditText) view.findViewById(R.id.et_licence_plate_3);
            AutoCompleteTextView mAcTxtOdometerValue = (AutoCompleteTextView) view
                    .findViewById(R.id.actxt_odometer_value);
            AutoCompleteTextView mAcTxtReportingCode = (AutoCompleteTextView) view
                    .findViewById(R.id.actxt_reporting_code);
            final NewCalibrationAdapter calibrationAdapter = new NewCalibrationAdapter(
                    newCalibrationActivity, calibrationDetails);
            final View expandedView = calibrationAdapter.getChildView(2, 0, true, view,
                    expandableListView);
            assertSame(view, expandedView);
            mAcTxtCarName.requestFocus();
            TouchUtils.tapView(this, mAcTxtCarName);
            sendKeys(KeyEvent.KEYCODE_H, KeyEvent.KEYCODE_U);
            getInstrumentation().waitForIdleSync();
        }
        else {
            Logger.e(tag, "##############", null);
        }
    }

0 个答案:

没有答案