registerIdlingResources deprecation replacement doesn’t work

1. Android Test Orchestrator. Android Test Orchestrator resolves your issue with IdlingResources test fails. dependencies { androidTestUtil ‘androidx.test:orchestrator:1.3.0’ } Configure your build.gradle: android { defaultConfig { testInstrumentationRunner “androidx.test.runner.AndroidJUnitRunner” testInstrumentationRunnerArguments clearPackageData: ‘true’ } testOptions { execution ‘ANDROIDX_TEST_ORCHESTRATOR’ } } Then run your tests: ./gradlew connectedCheck 2. Refactor the code The issue IdlingResources cause tests to fail. … Read more

Espresso – How can I check if an activity is launched after performing a certain action?

You can use: intended(hasComponent(YourExpectedActivity.class.getName())); Requires this gradle entry: androidTestCompile (“com.android.support.test.espresso:espresso-intents:$espressoVersion”) The import for the intended() and hasComponent() import static android.support.test.espresso.intent.Intents.intended; import static android.support.test.espresso.intent.matcher.IntentMatchers.hasComponent; as mentioned by Shubam Gupta please remember to call Intents.init() before calling intended(). You can eventually call it in the @Before method.

In Espresso, how to avoid AmbiguousViewMatcherException when multiple views match

EDIT: Someone mentioned in the comments that withParentIndex is now available, give that a try first before using the custom solution below. I was amazed that I couldn’t find a solution by simply providing an index along with a matcher (i.e. withText, withId). The accepted answer only solves the problem when you’re dealing with onData … Read more

Espresso – How to check if one of the view is displayed

It’s possible to catch the exceptions raised by Espresso like this: If you want to test if a view is in hierarchy: try { onView(withText(“Button”)).perform(click()); // View is in hierarchy } catch (NoMatchingViewException e) { // View is not in hierarchy } This exception will be thrown if the view is not in the hierarchy. … Read more

How to count RecyclerView items with Espresso

Here an example ViewAssertion to check RecyclerView item count public class RecyclerViewItemCountAssertion implements ViewAssertion { private final int expectedCount; public RecyclerViewItemCountAssertion(int expectedCount) { this.expectedCount = expectedCount; } @Override public void check(View view, NoMatchingViewException noViewFoundException) { if (noViewFoundException != null) { throw noViewFoundException; } RecyclerView recyclerView = (RecyclerView) view; RecyclerView.Adapter adapter = recyclerView.getAdapter(); assertThat(adapter.getItemCount(), is(expectedCount)); } … Read more

Android Marshmallow: Test permissions with Espresso?

With the new release of the Android Testing Support Library 1.0, there’s a GrantPermissionRule that you can use in your tests to grant a permission before starting any tests. @Rule public GrantPermissionRule permissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION); Kotlin solution @get:Rule var permissionRule = GrantPermissionRule.grant(android.Manifest.permission.ACCESS_FINE_LOCATION) @get:Rule must be used in order to avoid java.lang.Exception: The @Rule ‘permissionRule’ must … Read more

Espresso – TextView contains String

You can use the Hamcrest library. It has a method containsString. I believe it is in the Espresso library. You can static import it in your class: import static org.hamcrest.core.StringContains.containsString; Use containsString in your method on a TextView: textView.check(matches(withText(containsString(“Test”))));

How to assert inside a RecyclerView in Espresso?

Pretty easy. No extra library is needed. Do: onView(withId(R.id.recycler_view)) .check(matches(atPosition(0, withText(“Test Text”)))); if your ViewHolder uses ViewGroup, wrap withText() with a hasDescendant() like: onView(withId(R.id.recycler_view)) .check(matches(atPosition(0, hasDescendant(withText(“Test Text”))))); with method you may put into your Utils class. public static Matcher<View> atPosition(final int position, @NonNull final Matcher<View> itemMatcher) { checkNotNull(itemMatcher); return new BoundedMatcher<View, RecyclerView>(RecyclerView.class) { @Override public … Read more

Android Testing: UIAutomator vs Espresso

Actually, you don’t need to choose. UIAutomator and Espresso use the same instrumentation runner, so you can use commands from both of them in a single test. Espresso has variety of matchers, assertions and actions on UI, that automator doesn’t have: Espresso Cheat Sheet Espresso is running in separate thread and it is really fast … Read more

AndroidX : No instrumentation registered! Must run under a registering instrumentation

Update You should no longer encounter this error if youre using the latest gradle version. I also encountered this issue. If you look at migrating to Robolectric 4.0 here, it suggest to add the following line in your gradle.properties. android.enableUnitTestBinaryResources=true The problem is that, if you add this you your gradle.properties, it will output this … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)