Как написать контрольные примеры для радиогруппы с использованием эспрессо-тестирования - PullRequest
0 голосов
/ 16 апреля 2019

Мне нужно написать контрольные примеры для радиогруппы, использующей эспрессо в android-kotlin, и ниже - xml, который я использовал.

<RadioGroup
        android:id="@+id/radio_group"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:padding="15dp"
        android:checkedButton="@+id/production"
        tools:ignore="MissingConstraints">

        <TextView
            android:id="@+id/title"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/env_select"
            android:textStyle="bold"
            android:textSize="20sp"
            />

        <RadioButton
            android:id="@+id/production"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/env_production"
            />
        <RadioButton
            android:id="@+id/development"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/env_development"
            />
        <RadioButton
            android:id="@+id/testing"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/env_testing"
            />
    </RadioGroup>

Я пробовал некоторый код

       onView(withId(R.id.production))
               .check(matches(isChecked())); 
       onView(withId(R.id.development))
               .check(matches(not(isChecked()))); 
       onView(withId(R.id.testing))
               .check(matches(not(isChecked())));

Но это выглядит как android.support.test.espresso.NoMatchingViewException: No views in hierarchy found matching: with id:production

Пожалуйста, помогите мне написать контрольные примеры для того же

1 Ответ

0 голосов
/ 17 апреля 2019

Вы можете попробовать этот новый метод теста:

    @Test
    fun checkRadioButtons() {
        // 1. Launching the activity with radio button
        ActivityScenario.launch(YourActivityName::class.java)

        // 2. Checking if radio group present
        onView(withId(R.id.radio_group))
                .check(matches(isDisplayed()))

        // You can also check for radio buttons similarly...

        // 3. Click one of the button and check
        onView(withId(R.id.production))
                .perform(click())

        onView(withId(R.id.production))
                .check(matches(isChecked()))

        onView(withId(R.id.testing))
                .check(matches(isNotChecked()))

        onView(withId(R.id.development))
                .check(matches(isNotChecked()))
    }

Надеюсь, это поможет!

...