Тестирование инструментов счетчиками с использованием специального массива Adapter с эспрессо

Итак, я пытаюсь написать несколько тестов инструментов для деятельности, в которой есть несколько блесен. Эти счетчики используют собственные arrayAdapters, так что я могу подключить их к ArrayLists некоторых классов моделей.

Адаптер для одного блесны:

/**
* Custom spinner adapter for car selection.
*
* Source: http://stackru.com/questions/1625249/android-how-to-bind-spinner-to-custom-object-list
*/

public class MyCarSpinnerAdapter extends ArrayAdapter<Car> {

// Your sent context
private Context context;
// Your custom values for the spinner (User)
private ArrayList<Car> values;

public MyCarSpinnerAdapter(
        Context context,
        int textViewResourceId,
        ArrayList<Car> values
) {
    super(context, textViewResourceId, values);
    this.context = context;
    this.values = values;
}

public int getCount(){
    return values.size();
}

public Car getItem(int position){
    return values.get(position);
}

// And the "magic" goes here
// This is for the "passive" state of the spinner
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    // I created a dynamic TextView here, but you can reference
    // your own custom layout for each spinner item
    TextView label = new TextView(this.context);
    label.setTextColor(Color.BLACK);
    // Then you can get the current item using the values array
    // (Users array) and the current position. You can NOW reference
    // each method you has created in your bean object (User class)
    label.setText(
            values.get(position).getManufacturer()
                    + " "
                    + this.values.get(position).getModel()
    );

    // And finally return your dynamic (or custom) view for each spinner item
    return label;
}

// And here is when the "chooser" is popped up
// Normally is the same view, but you can customize it if you want
@Override
public View getDropDownView(int position, View convertView,
                            ViewGroup parent) {
    TextView label = new TextView(context);
    label.setTextColor(Color.BLACK);
    label.setText(
            this.values.get(position).getManufacturer()
                    + " "
                    + this.values.get(position).getModel()
    );

    return label;
}

@Override
public final String toString() {
    return "this is the my car spinner adapter string";
}
}

Тест:

/**
 * Initial values testing.
 */
@Test
public void initialSettingsTest() {
    ViewInteraction carSpinner = onView(withId(R.id.MyCarActivity_ManufacturerSpinner));
    ViewInteraction batSpinner = onView(withId(R.id.MyCarActivity_BatterySpinner));
    ViewInteraction tireSpinner = onView(withId(R.id.MyCarActivity_TireSpinner));

    carSpinner.check(matches(withSpinnerText("Ford Magic")));
    batSpinner.check(matches(withSpinnerText("10.0 kwh")));
    tireSpinner.check(matches(withSpinnerText("1.0 roll")));
}

Результат:

android.support.test.espresso.base.DefaultFailureHandler$AssertionFailedWithCauseError: 'with text: is "Ford Magic"' doesn't match the selected view.
Expected: with text: is "Ford Magic"
Got: "AppCompatSpinner{id=2131492994, res-name=MyCarActivity_ManufacturerSpinner, visibility=VISIBLE, width=618, height=72, has-focus=false, has-focusable=true, has-window-focus=true, is-clickable=true, is-enabled=true, is-focused=false, is-focusable=true, is-layout-requested=false, is-selected=false, root-is-layout-requested=false, has-input-connection=false, x=462.0, y=147.0, child-count=1}"

Что вызывает это? Как я могу проверить, что значения в счетчике соответствуют ожидаемым?

0 ответов

Другие вопросы по тегам