问题
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