Questions tagged [android-instrumentation]

Base class for implementing application instrumentation code.

Base class for implementing application instrumentation code.

When running with instrumentation turned on, this class will be instantiated for you before any of the application code, allowing you to monitor all of the interaction the system has with the application. An Instrumentation implementation is described to the system through an AndroidManifest.xml's <instrumentation> tag.

Reference: http://developer.android.com/reference/android/app/Instrumentation.html

526 questions
22
votes
3 answers

Android Studio -- clear application data for Instrumentation Test

How can I get Android Studio (AndroidJunitRunner) to clear application data preceding an instrumentation test without manually running adb command? I discovered that android.support.test.runner.AndroidJUnitRunner kind of cheats -- it never actually…
21
votes
1 answer

Run an instrument test from within app and wait for result

I am developing a QA automation solution that can record/playback QA tests on Android. A key business requirement is to have no dependency on a connected PC while playing back the recorded test. To that end, I'm trying to run an Instrumentation test…
20
votes
3 answers

Reset app state between InstrumentationTestCase runs

One of my QA engineers is supporting an app with a fairly large codebase and a lot of different SharedPreferences files. He came to me the other day asking how to reset the application state between test runs, as if it had been…
Turnsole
  • 3,422
  • 5
  • 30
  • 52
19
votes
1 answer

Where is the output from an android instrumented test?

I managed to get gradle cC to work. My test just prints out and logs one line of text. grep -r text * fails. where is the system.out and logging output? thanks edit: i found the output for the unit tests (it's in .../app/build/test-results/). but…
Ray Tayek
  • 9,841
  • 8
  • 50
  • 90
18
votes
5 answers

Android studio - androidTest folder is missing

I'm working on automation test using Espresso. The folder in which Instrumentation test classes can be written is missing Screenshot of the project I tried by adding android{ sourceSets{ main { java.srcDirs = ['src/main/java'] } …
Suhas
  • 231
  • 1
  • 3
  • 10
17
votes
4 answers

How to disable animations in code when running Espresso tests

Has anybody managed to disable animations through code when running Espresso tests? I've been trying to follow the instructions in this webpage (linked to from here): https://code.google.com/p/android-test-kit/wiki/DisablingAnimations…
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…
14
votes
4 answers

Android instrumentation test fails to install APK

I want to run instrumentation test as part of my CI pipeline but when I run the tests they fail because the APK could not be installed (as far as I understood): > Task :app:connectedDebugAndroidTest FAILED Mar 18, 2022 3:00:59 PM…
14
votes
1 answer

How to run single test class in Android using Gradle command?

In my Android application I have several test classes. If I run following command ./gradlew connectedAndroidTest it runs all the test cases inside the android test folder and generate test report for all test classes but I need to test a specific…
14
votes
2 answers

Activity in androidTest not getting launched by ActivityTestRule

I want to test a fragment in test activity. I added TestTragmentActivity to androidTest along with AndroidManifest.xml file. But when I try to use this activity via an ActivityTestRule it gives following error: java.lang.RuntimeException: Could not…
14
votes
3 answers

How can I check the expected intent sent without actually launching activity in Espresso?

I have a UI test which clicks a button, and then launch a new Activity in its onClickListener. The test checks whether expected intent is sent or not. My problem is, I want to test whether expected intent is sent without actually launching the…
14
votes
1 answer

How to use files in instrumented unit tests

I've got this project which processes images. The library I use to do most of the actual image processing requires me to run these tests on a Android device or emulator. I'd like to provide a few test images which it should process, the thing is…
Mathijs
  • 367
  • 1
  • 4
  • 14
13
votes
1 answer

AndroidJunit4 doesn't accept space function test name?

I have the following test, where the test name is with space and backtick for my instrumental test @RunWith(AndroidJUnit4::class) class MyTestClass { @Rule @JvmField var activityRule: ActivityTestRule =…
Elye
  • 53,639
  • 54
  • 212
  • 474
13
votes
1 answer

How to place Android (instrumentation) test files outside of project directory?

I have an Android project (generated by Cordova) that I want to add (instrumentation) tests to. It has only one MainActivity.java that should be tested. Normally this means adding some dependencies to build.gradle and creating a file…
13
votes
1 answer

"No tests found" for instrumentation tests for Lollipop and above

My instrumentation based (espresso) tests don't run on Lollipop+ devices and emulators. They correctly run on any other platform. I have the same symptoms as the guy in this thread -…
1
2
3
35 36