Android Studio Instrumentation testing build variant

You can do testing on a different build variant; but only on one. The default is debug. See this: https://developer.android.com/studio/build/gradle-tips#change-the-test-build-type Currently only one Build Type is tested. By default it is the debug Build Type, but this can be reconfigured with: android { … testBuildType “staging” }

Can I extend a custom Application in Espresso?

With a custom instrumentation runner, you can override newApplication and have it instantiate something other than the default application from the manifest. public class MyRunner extends AndroidJUnitRunner { @Override public Application newApplication(ClassLoader cl, String className, Context context) throws Exception { return super.newApplication(cl, MyCustomEspressoApplication.class.getName(), context); } } Be sure to update testInstrumentationRunner with your custom runner’s … Read more

Android Espresso check selected spinner text

Replace withText() with withSpinnerText() onView(withId(spinnerId)).perform(click()); onData(allOf(is(instanceOf(String.class)), is(selectionText))).perform(click()); onView(withId(spinnerId)).check(matches(withSpinnerText(containsString(selectionText)))); Reference: https://code.google.com/p/android-test-kit/issues/detail?id=85

Espresso intent test failing

I had the same problem and solved it by using IntentsTestRule instead of ActivityTestRule. IntentsTestRule is a subclass of ActivityTestRule. Set up your @Rule which creates the activity like so: @Rule public IntentsTestRule<MyActivity> mActivity = new IntentsTestRule<MyActivity>(MyActivity.class) { @Override protected Intent getActivityIntent() { … } }; See the following project for more information: https://github.com/googlesamples/android-testing/tree/master/ui/espresso/IntentsBasicSample

Espresso testing disable animation

Make sure to keep your plugin updated: buildscript { repositories { google() gradlePluginPortal() } dependencies { classpath ‘com.android.tools.build:gradle:3.3.0’ } } Use the new flag in testOptions called animationsDisabled: android { … testOptions { animationsDisabled = true } } Source: https://google.github.io/android-gradle-dsl/current/com.android.build.gradle.internal.dsl.TestOptions.html#com.android.build.gradle.internal.dsl.TestOptions:animationsDisabled You can try turning off animations on your device/emulator manually: To avoid flakiness, we highly … Read more

Click on not fully visible imageButton with Espresso

None of the above worked for me. Here is a custom matcher that completely removes that constraint and allows you to click on the view onView(withId(yourID)).check(matches(allOf( isEnabled(), isClickable()))).perform( new ViewAction() { @Override public Matcher<View> getConstraints() { return ViewMatchers.isEnabled(); // no constraints, they are checked above } @Override public String getDescription() { return “click plus button”; … Read more

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