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
33
votes
8 answers

Espresso how to test if Activity is finished?

I want to assert that my Acitivty that I am currently testing is finished when certain actions are performed. Unfortunately so far I am only to assert it by adding some sleep at the end of the test. Is there a better way ? import…
32
votes
5 answers

Start Activity for testing

I 've got a Quiz app using Realm db. Every time the user selects an answer she clicks a button and new text for Question appears. Thats it until she reaches the end where I start a new Activity and display a score based on correct answers. How…
t0s
  • 1,201
  • 5
  • 19
  • 28
31
votes
6 answers

Gradle: No tests found

When I am trying to run Android tests by executing: ./gradlew connectedDebugAndroidTest The following error occurs: com.android.builder.testing.ConnectedDevice > No tests found.[devicename] FAILED No tests found. This usually means that your test…
31
votes
3 answers

Android Studio Instrumentation testing build variant

So I am trying to write instrumentation tests using a custom build variant, mock. In this build variant I mocked up my classes and server. When I try using the mock build myself it works fine, but I can't seem to use my mock build for testing.…
31
votes
5 answers

Android: Writing test cases for Fragments

In my previous projects I've done most of the work through Activities and used ActivityInstrumentationTestCase2 as per the document: http://developer.android.com/tools/testing/activity_testing.html I have an idea how to work with Activity Test…
AnswerDroid
  • 1,873
  • 2
  • 33
  • 52
31
votes
3 answers

Click by bounds / coordinates

I know it is possible for Espresso to click by bounds the way UiAutomator does. (x and y coordinates) I have read through the documentation but I can't seem to find it. Any help is appreciated. Thanks Edit I found this link, but no examples how to…
Chad Bingham
  • 32,650
  • 19
  • 86
  • 115
30
votes
2 answers

How to properly learn Android testing?

What are good ways to learn Android testing? I'm interested in learning Android testing, I don't actually do TDD but write the tests and code together. I read all the information at http://developer.android.com/tools/testing/index.html and the…
Gal Ben-Haim
  • 17,433
  • 22
  • 78
  • 131
29
votes
2 answers

Cannot use Kotlin backticked method names in androidTest - bad descriptor exception

In my unit tests I use Kotlin's backticked methods for better readability, e.g. @Test fun `Foo should return bar`() It works nice and well for tests in /src/test directory, but when I try to do the same in /src/androidTest I get an…
Michał Klimczak
  • 12,674
  • 8
  • 66
  • 99
29
votes
3 answers

How to exclude Dagger2 classes from test coverage

Is there any option to exclude Dagger2 classes from test coverage report in Android Studio
Mladen Rakonjac
  • 9,562
  • 7
  • 42
  • 55
29
votes
4 answers

Android Espresso: How do I test a specific Fragment when following one activity to several fragment architecture

My app consists of one Activity for many Fragments. I wish to use Espresso to test the UI of the Fragments. However I ran into a problem. How can I test a Fragment which is not added to an Activity in onCreate. All examples I have seen with…
Ersen Osman
  • 7,067
  • 8
  • 47
  • 80
29
votes
2 answers

Gradle: How to display androidTest results in the console?

As explained in other threads Gradle can be configured to log test results into the console: Gradle Android: How to Display test results without using --info Gradle: How to Display Test Results in the Console in Real Time? Output unit testing…
JJD
  • 50,076
  • 60
  • 203
  • 339
29
votes
5 answers

Testing database on Android: ProviderTestCase2 or RenamingDelegatingContext?

I've implemented access to a database using SQLiteOpenHelper from the android.database package within some classes (with pattern DAO). I wrote some junit tests for these classes using an AndroidTestCase but this causes the tests to use the same…
Giorgio
  • 13,129
  • 12
  • 48
  • 75
29
votes
2 answers

how to get text from textview using espresso

I want get text string shown in a textview in LinearLayout. can espresso do that? If not, is there other way to do that or can I use android api in espresso test case? I am using API 17 18 or newer, espresso 1.1(It should be the latest one.). I have…
Nick Dong
  • 3,638
  • 8
  • 47
  • 84
29
votes
0 answers

Google Play Alpha/Beta testing link is broken

I have uploaded an apk file to the Alpha Testing tab in the developer console and added a google group of my Alpha testers. When trying to enter the generated URL I get page not found error (404). Is it relevant to the fact that my app is still in…
Daniel L.
  • 5,060
  • 10
  • 36
  • 59
28
votes
1 answer

What is the added advantage of using Bazel over Gradle?

I was reading about the Android Testing Samples project and noticed that a "new" build tool named Bazel is being used for building Android projects: Experimental Bazel Support Some of these samples can be built with Bazel on Linux. These samples…
shizhen
  • 12,251
  • 9
  • 52
  • 88