Questions tagged [android-testing]

The Android testing framework

The Android testing framework, an integral part of the development environment, provides an architecture and powerful tools that help you test every aspect of your application at every level from unit to framework.

The testing framework has these key features:

  • Android test suites are based on JUnit. You can use plain JUnit to test a class that doesn't call the Android API, or Android's JUnit extensions to test Android components. If you're new to Android testing, you can start with general-purpose test case classes such as AndroidTestCase and then go on to use more sophisticated classes.
  • The Android JUnit extensions provide component-specific test case classes. These classes provide helper methods for creating mock objects and methods that help you control the lifecycle of a component.
  • Test suites are contained in test packages that are similar to main application packages, so you don't need to learn a new set of tools or techniques for designing and building tests.
  • The SDK tools for building and tests are available in Eclipse with ADT, and also in command-line form for use with other IDEs. These tools get information from the project of the application under test and use this information to automatically create the build files, manifest file, and directory structure for the test package.
  • The SDK also provides monkeyrunner, an API for testing devices with Python programs, and UI/Application Exerciser Monkey, a command-line tool for stress-testing UIs by sending pseudo-random events to a device.
2161 questions
329
votes
8 answers

AndroidJUnit4.class is deprecated: How to use androidx.test.ext.junit.runners.AndroidJUnit4?

For my instrumentation tests I was using @RunWith(AndroidJUnit4.class) from import androidx.test.runner.AndroidJUnit4; in order to establish my test cases. Now this line gets marked as deprecated with the hint to use AndroidJUnit4 from import…
Marcel Gangwisch
  • 8,856
  • 4
  • 23
  • 32
165
votes
5 answers

How to Enable Internal App Sharing for Android?

I have uploaded the Android App Bundle in Play console for Alpha testing but when I open the testing URL it is showing below dialog.
148
votes
4 answers

What's the difference between src/androidtest and src/test folders?

In a project, in Android Studio, by default, there are two test folders. The first is src/androidTest. This folder already existed in the previous version of Android Studio. Nevertheless, there is now a new test folder, by default, src/test, and new…
lopez.mikhael
  • 9,943
  • 19
  • 67
  • 110
118
votes
2 answers

Google Espresso or Robotium

I have to use Automated UI test tool and I am confused between using Robotium vs Google Espresso. What are the major differences between the two? Are there features that exist in one but not the other?
Androidme
  • 3,145
  • 3
  • 24
  • 27
103
votes
5 answers

matches(not(isDisplayed())) fails with NoMatchingViewException

I am trying to test the absence of the UI view. The view selector is as follows: public static ViewInteraction onMyTestUi() { return onView(withId(R.id.myTestId)); } The selector works fine to check if the view is displayed, but gives error on…
91
votes
1 answer

Testing ViewPager (and CursorLoader) with Robolectric

Does anyone know how to test the following setup using Robolectric? Fragment containing a ViewPager, data loaded with a CursorLoader. With the code below, the CursorLoader is never pushed into the adapter for the view pager. I get stuck at the…
Corey Scott
  • 2,430
  • 3
  • 28
  • 33
87
votes
4 answers

Confused about testCompile and androidTestCompile in Android Gradle

I'm new to testing world and even more to Android testing world. While doing research on Robolectric that aids with tests on android one thing confuses me the most. Sometimes on the web I see people using testCompile keyword in dependencies of the…
Lucas
  • 3,521
  • 3
  • 27
  • 39
81
votes
14 answers

How do you test an Android application across multiple Activities?

We are building a complex Android application consisting of many screens and workflows spread across many Activities. Our workflows are similar to what you might see on a Bank's ATM machine, for example, there is an Activity to login in that…
SingleShot
  • 18,821
  • 13
  • 71
  • 101
70
votes
10 answers

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

In my test, after one action, there are two possible views which can appear and both of them are correct. How can I check if one of the view is displayed. For a single view I can check with is Displayed(). But that would fail if other view is…
user846316
  • 6,037
  • 6
  • 31
  • 40
67
votes
6 answers

androidx.test.InstrumentationRegistry is deprecated

Switched to AndroidX and received deprecated: import androidx.test.InstrumentationRegistry. If I made next import: import androidx.test.platform.app.InstrumentationRegistry I can't use getContext(). Ex: val context =…
Morozov
  • 4,968
  • 6
  • 39
  • 70
61
votes
15 answers

Android alpha testing "Item not found"

I have published my app for alpha testing, but not able to download it from play store. I have opened the url "https://play.google.com/apps/testing/com.*" and accepted to be a tester and now it shows me "you are a tester". But when I click on the…
Arunita
  • 636
  • 1
  • 5
  • 6
57
votes
2 answers

registerIdlingResources deprecation replacement doesn't work

I'm trying to replace my Espresso registerIdlingResources and unregisterIdlingResources deprecated method by using IdlingRegistry method according to Android documentation. Some of my tests worked before the update and no longer work now. These…
Crisic
  • 1,181
  • 1
  • 9
  • 27
57
votes
4 answers

How to use VisibleForTesting for pure JUnit tests

I´m running pure JUnit4 java tests over my pure java files on my project but I can't find a way to use @VisibleForTesting clearly without making the thing manually public. Ex: @VisibleForTesting public Address getAddress() { return…
Daniel Gomez Rico
  • 15,026
  • 20
  • 92
  • 162
56
votes
10 answers

Test running failed: Unable to find instrumentation info for: ComponentInfo{} -- error trying to test in IntelliJ with Gradle

Everytime I try to run my tests the console says this: Running tests Test running startedTest running failed: Unable to find instrumentation info for: ComponentInfo{com.employeeappv2.employeeappv2.test/android.test.InstrumentationTestRunner} Empty…
njthoma
  • 785
  • 3
  • 7
  • 11
51
votes
4 answers

Providing test data for SharedPreferences for Robolectric

Just started to use Robolectric and it seems to be pretty much what I need. However, I've hit a bit of a roadblock with regards to the use of SharedPreferences. I have two tests cases Activity expects a new/empty sharedPreferences Activity…
pyko
  • 3,399
  • 5
  • 26
  • 31
1
2 3
99 100