Espresso - Radio button, how to choose data

霸气de小男生 提交于 2020-01-06 06:19:11

问题


I'm using espresso for testing my android app. I have a radio group in my layout file

 <ScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <RadioGroup
            android:id="@+id/radio_number_group"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </ScrollView>

And radio button is added programmatically. The data is fetched from an API and added!!

if (mvns.size() > 0) {
        radioGroup.removeAllViews();
        for (String s : mvns) {
            RadioButton rb = new RadioButton(this);
            RadioGroup.LayoutParams lp = new RadioGroup.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
           // rb.setId(R.id.radio_number_button);
            lp.setMargins(20, 10, 0, 40);
            rb.setLayoutParams(lp);
            rb.setChecked(false);
            String number = Utils.formatNumber(s, countryCode);
            rb.setText(number.replaceAll(" ", "-"));
            rb.setTextSize(16);
            rb.setTag(s);
            rb.setGravity(Gravity.CENTER_VERTICAL);
            rb.setPadding(20, 0, 0, 50);
            rb.setBackground(getResources().getDrawable(R.drawable.division_view_background));
            rb.setButtonDrawable(R.drawable.radio_button_selector);
            rb.setTextColor(Color.BLACK);
            radioGroup.addView(rb);
        }

So, while testing using espresso I tried by setting ID, I got an error! meaning is same ID set to all radioButtons ( I have 5 data in my list).

How do I write test cases for this??

来源:https://stackoverflow.com/questions/49606500/espresso-radio-button-how-to-choose-data

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!