insturmenation test are failing randomly with mockserver
Hi Mate,
My test are failing randomly
Workflow Success: https://github.com/TheReprator/Wipro/runs/2911975969?check_suite_focus=true
Workflow Fail: https://github.com/TheReprator/Wipro/runs/2911975942?check_suite_focus=true
Exception logs: `reprator.wipro.factlist.test.FactListKaspressoTest > load_item_successfully_in_recyclerview_with_error_on_pullToRefresh[test(AVD) - 6.0] FAILED androidx.test.espresso.NoMatchingViewException: No views in hierarchy found matching: (an instance of com.google.android.material.snackbar.Snackbar$SnackbarLayout)
reprator.wipro.factlist.test.FactListKaspressoTest > loadErrorViewOnLaunch_withSuccessfulReload[test(AVD) - 6.0] FAILED junit.framework.AssertionFailedError: 'is displayed on the screen to the user' doesn't match the selected view. Expected: is displayed on the screen to the user
Task :appModules:factList:connectedDebugAndroidTest FAILED`
Repo: https://github.com/TheReprator/Wipro Branch: codeCoverage workflow: push.yml
Looking forward for a solution.
Regards, Vikram Singh
Flaky behaviour is rather common for complex UI tests running on Android Emulators, especially in CI environments. You should use a retry mechanism, e.g. a RetryTestRule that retries a failing test for a fixed number of times. Additionally, you can also use a waitForView instead of onView(...).check(matches(...)). onView().check(matches(..)) will find the view and check assertions. It fails immediately if the view state is not as expected. waitForView combines both steps and waits for a view that matches the assertions, e.g.
onView(withId(R.id.test)).check(matches(isDisplayed()))
// becomes
waitForView(withId(R.id.test), isDisplayed())
I've also found that in my case Android <= 28 works better because the instrumentation process crashes randomly on Android 29+.