Issue
I have the following UI test file and extensions file for an app I am making:
package com.realtomjoney.pyxlmoose.activities.`2_canvas`
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.assertion.ViewAssertions.matches
import androidx.test.espresso.matcher.ViewMatchers.*
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.filters.LargeTest
import com.realtomjoney.pyxlmoose.R
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import androidx.test.internal.runner.junit4.AndroidJUnit4ClassRunner
import com.realtomjoney.pyxlmoose.AndroidTestUtilityFunctions
import com.realtomjoney.pyxlmoose.activities.canvas.CanvasActivity
@LargeTest
@RunWith(AndroidJUnit4ClassRunner::class)
class CanvasActivityTestsOnFindAndReplaceButtonTap {
@get:Rule
var activityTestRule = ActivityScenarioRule(CanvasActivity::class.java)
@Test fun uitest_doneButton_isNotDisplayed_after_findAndReplaceButton_isPressed() {
AndroidTestUtilityFunctions.goToFindAndReplaceFragment()
onView(withId(R.id.activityCanvas_doneButton)).check(matches(withEffectiveVisibility(Visibility.GONE)))
}
@Test fun uitest_colorPickerRecyclerView_isNotDisplayed_after_findAndReplaceButton_isPressed() {
AndroidTestUtilityFunctions.goToFindAndReplaceFragment()
onView(withId(R.id.activityCanvas_colorPickerRecyclerView)).check(matches(withEffectiveVisibility(Visibility.GONE)))
}
@Test fun uitest_titleTextView_isNotDisplayed_after_findAndReplaceButton_isPressed() {
AndroidTestUtilityFunctions.goToFindAndReplaceFragment()
onView(withId(R.id.activityCanvas_canvasTitleEditText)).check(matches(withEffectiveVisibility(Visibility.GONE)))
}
@Test fun uitest_colorSwapButton_isNotDisplayed_after_findAndReplaceButton_isPressed() {
AndroidTestUtilityFunctions.goToFindAndReplaceFragment()
onView(withId(R.id.activityCanvas_colorSwapButton)).check(matches(withEffectiveVisibility(Visibility.GONE)))
}
@Test fun uitest_colorPrimarySelected_isNotDisplayed_after_findAndReplaceButton_isPressed() {
AndroidTestUtilityFunctions.goToFindAndReplaceFragment()
onView(withId(R.id.activityCanvas_colorPrimaryView)).check(matches(withEffectiveVisibility(Visibility.GONE)))
}
@Test fun uitest_colorSecondarySelected_isNotDisplayed_after_findAndReplaceButton_isPressed() {
AndroidTestUtilityFunctions.goToFindAndReplaceFragment()
onView(withId(R.id.activityCanvas_colorSecondaryView)).check(matches(withEffectiveVisibility(Visibility.GONE)))
}
}
object AndroidTestUtilityFunctions {
private const val defaultProjectName = "Unnamed Project"
private const val defaultProjectSpanCount = 5
fun goToFindAndReplaceFragment() {
onView(withId(R.id.activityCanvas_canvasToolsScrollView)).perform(swipeLeft())
onView(withId(R.id.activityCanvas_findAndReplaceButton)).perform(click())
}
fun createNewProject(projectName: String = defaultProjectName, spanCount: Int = defaultProjectSpanCount) {
onView(withId(R.id.activityMain_newProjectButton)).perform(click())
onView(withId(R.id.fragmentNewCanvas_projectTitleTextInputEditText)).perform(replaceText(projectName))
onView(withId(R.id.fragmentNewCanvas_spanCountTextInputEditText)).perform(replaceText(spanCount.toString()))
onView(withId(R.id.fragmentNewCanvas_doneButton)).perform(click())
}
}
For some reason, when I run the UI tests, I get the following annoying exception:
java.lang.IllegalAccessError: Illegal class access: 'androidx.test.core.app.ListFuture' attempting to access 'androidx.concurrent.futures.DirectExecutor' (declaration of 'androidx.test.core.app.ListFuture' appears in /data/app/~~xOjrSE9BCeINue7sOBFVJw==/com.realtomjoney.pyxlmoose.test-VqvV0FRJD_fIuyk2Jiuyyw==/base.apk)
at androidx.test.core.app.ListFuture.directExecutor(ListFuture.java:139)
at androidx.test.core.app.ListFuture.init(ListFuture.java:101)
at androidx.test.core.app.ListFuture.<init>(ListFuture.java:84)
at androidx.test.core.app.DeviceCapture$forceRedrawGlobalWindowViews$1.run(DeviceCapture.kt:151)
at android.os.Handler.handleCallback(Handler.java:938)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loopOnce(Looper.java:201)
at android.os.Looper.loop(Looper.java:288)
at android.app.ActivityThread.main(ActivityThread.java:7842)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
I have no idea why this is happening, I've tried for a couple of weeks to solve it but with no luck - I am still getting the same exception whenever I try and execute my UI tests. This is extremely bad as I am actually committing faulty code on a regular basis! I really need this issue fixed.
Solution
I had this same issue, too. I spent a ton of time researching it, and ultimately found that your issue stems from this: https://issuetracker.google.com/issues/204506297
Essentially, that version of the Espresso library tries to use an enum from another library that it does not have scoping access to. They have fixed the issue here: https://github.com/android/android-test/pull/1174
Unfortunately, at the time of writing 3.5.0-alpha03
is the latest version. So, you can either wait for alpha04
/beta01
or downgrade back to 3.4.0
until the issue is fixed.
Answered By - Oliver Spryn
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.