Questions tagged [android-espresso]

Espresso is a library which is used to write Android UI tests. It is also known as Google's Testing Tools For Android

Also called android-test-kit, Espresso helps to create faster UI tests for Android.

The core API is small, predictable, and easy to learn and yet remains open for customization. Espresso tests state expectations, interactions, and assertions clearly without the distraction of boilerplate content, custom infrastructure, or messy implementation details getting in the way.

Espresso tests run optimally fast! Leave your waits, syncs, sleeps, and polls behind and let Espresso gracefully manipulate and assert on the application UI when it is at rest. Enjoy writing and executing your tests today - try a shot of Espresso!

Useful links

3335 questions
16
votes
4 answers

Can't get ApplicationContext in Espresso tests

I keep getting the following error when running my Espresso tests: Attempt to invoke virtual method 'android.content.Context android.app.Instrumentation.getTargetContext()' on a null object reference @RunWith(AndroidJUnit4.class) public class…
Nxt3
  • 1,970
  • 4
  • 30
  • 52
16
votes
2 answers

How to set current tab in viewpager with tablayout

I have a custom viewpager (with swiping disabled for reasons) working with a tablayout. The content changes based on which tab is selected. I want to test this using espresso: 1) Click on a particular tab 2) Check some data in a particular page of…
16
votes
4 answers

Testing ViewPager with multiple fragments using android espresso

I am trying to test my app which uses ViewPager. Each page contains fragments but these fragments are not always visible. I want to check visibility of a fragment in the currently visible page. onView(withId(R.id.container_weather)) …
Ubaier Bhat
  • 854
  • 13
  • 33
16
votes
6 answers

Android Studio Espresso Testing Error: Empty Test Suite

I keep running into the following error when trying to execute my tests in Android Studio: Test running failed: Unable to find instrumentation info for: ComponentInfo{.test/android.support.test.runner.AndroidJUnitRunner} My test class is in the…
Isaac
  • 163
  • 1
  • 1
  • 5
16
votes
10 answers

Espresso - typeText not working

I'm trying to type some text inside an EditText: public void testSearch() { onView(withId(R.id.titleInput)).perform(typeText("Engineer")); onView(withId(R.id.titleInput)).check(matches(withText("Engineer"))); } I see…
Eduard
  • 3,482
  • 2
  • 27
  • 45
15
votes
5 answers

Unknown platform error occurred when running the UTP test suite

When trying to build android app Espresso Instrumentation Tests with circleci Unknown platform error occurred when running the UTP test suite. Task :app:connectedDebugAndroidTest FAILED Test results saved as…
RockyGlobal
  • 525
  • 5
  • 13
15
votes
1 answer

Hilt viewmodel injection into instrumentation tests

I was searching quite a lot for how to inject ViewModel into tests so I can test it. Lets say the viewmodel have a constructor injection with some business logic interactor. I can inject it into fragments easily but no success in…
Alex
  • 327
  • 3
  • 11
15
votes
0 answers

java.lang.AssertionError: Activity never becomes requested state

I got following error when i executed my unit test java.lang.AssertionError: Activity never becomes requested state "[CREATED, STARTED, RESUMED, DESTROYED]" (last lifecycle transition = "PRE_ON_CREATE") at…
Cyrus
  • 8,995
  • 9
  • 31
  • 58
15
votes
1 answer

How to make android:usesCleartextTraffic="true" only for instrumentation tests?

I'm using RESTMock for my instrumentation tests, but it only works if I set usesCleartextTraffic to true in my manifest. I only want that to be true for instrumentation tests, though. Is there a way to do that? I tried creating a new manifest file…
15
votes
4 answers

Is it possible to use Espresso's IdlingResource to wait until a certain view appears?

In my test I have a stage where after pressing a button application does a lot of asynchronous calculations and requests to the cloud service, after which it displays a certain view. Is it possible to use Espresso's IdlingResource implementation to…
Rinat Veliakhmedov
  • 1,021
  • 1
  • 19
  • 36
15
votes
5 answers

Android Studio : Cannot resolve symbol "Truth" (Truth library)

After coming across this gist : https://gist.github.com/chemouna/00b10369eb1d5b00401b, I noticed it was using the Google Truth library : https://google.github.io/truth/. So I started by following the procedure to add the library in my build.gradle…
ysoa
  • 153
  • 1
  • 5
15
votes
4 answers

Android Studio - Kotlin Tests Throwing - Class not found - Empty test suite

When trying to run espresso tests written in Kotlin on Android Studio (as far as 3.2 Canary 9), I'm getting the error: Process finished with exit code 1 Class not found: "com.myproject.directoryofwinning.VerifyAppIsAwesomeTest"Empty test…
user1228891
  • 636
  • 8
  • 17
15
votes
1 answer

Espresso can't find a View inside a custom view class

I have a custom View class public class Foo extends RelativeLayout{...} which have an EditText in it. The Foo class have a XML layout inflated and its EditText also have an id but its not able to find the EditText I'm using this Espresso…
user5366495
15
votes
3 answers

Android: Espresso, No views in hierarchy found matching

I'm testing the launch of a fragment inside my activity, so after performing a click on button that going to launch the fragment, I tested the existing of a text on view inside the launched fragment, but the test fail even though that fragment is…
Abdennacer Lachiheb
  • 4,388
  • 7
  • 30
  • 61
15
votes
6 answers

Run espresso test multiple times

Sometimes I faced with rare bug in my application. But I can't reproduce it as it's very rare. So, I decided to write simple espresso test: @RunWith(AndroidJUnit4::class) @LargeTest class MainActivityTest { val password = "1234" @Rule…
Alexandr
  • 3,859
  • 5
  • 32
  • 56