Wednesday 21 October 2020

How to test vector drawable visible in fragment scenario test?

I have written some fragment scenario tests which would take screenshot and some click event. Few of the test are failed because the imageview is not shown.

It seems the testing activity in the testing library (https://developer.android.com/training/basics/fragments/testing) using FragmentActivity, which is not a subclass from AppCompatActivity. In result, those image view is not visible. I could add attribute android:src to make it visible in test, but it would be an ugly fix. Is there any other solution for it?

Appreciate any comment or advice for it.

view_item.xml

<ImageView
                android:id="@+id/ivRemove"
                android:layout_width="16dp"
                android:layout_height="16dp"
                android:layout_marginStart="@dimen/spacing_16dp"
                android:layout_marginTop="@dimen/spacing_16dp"
                android:layout_marginBottom="@dimen/spacing_16dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/ic_remove" />

build.gradle.kts

defaultConfig {
        this.testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
        this.vectorDrawables.useSupportLibrary = true
    }


from How to test vector drawable visible in fragment scenario test?

No comments:

Post a Comment