7

Is it not possible to automation android app using espresso without source code. Gradle expects a structure like this:

src/main/
src/androidTest/

But I would like to run these automation tests on a different version of the app? Is this possible just by installing the app and running the tests?

Here it says its not possible:

Automation of Android APK with Espresso

Community
  • 1
  • 1
Virus
  • 3,215
  • 7
  • 29
  • 46

4 Answers4

6

The answer is yes, you can run automation test using Espresso without app source code.

Espresso is based on Android instrumentation framework, which means the automation test is built into a single test apk. This test apk is different from normal application apk:

  1. There is an instrumentation registered in AndroidManifest.xml, which will be registered to Android system once test apk is installed

  2. The test apk must be signed using the same signature with the application apk, in order to run automation test

  3. The test apk runs in the same process as application apk

Above are the only requirements of any instrument based test framework has. So there is no dependency of source code.

But why we find most of the Espresso tutorials are mixed with source code? Because it will make the test simpler:

  1. You can easily control the activity lifecycle using class ActivityTestRule.

  2. You can test application defined classes easily.

  3. You can test UI widgets using widget id

On the contrary, you have to write lots of reflection code to get the classes you need if you don't compile with source code. For example:

  1. You have to use Class.forName to load the entrance activity and launch it

  2. You have to use Java reflection to test application defined classes

  3. You have to use literal information to find UI widgets, because you don't have the id of the UI widgets

To sum up, it is OK to run Espresso automation test without application source code, but it's much harder and make test codes ugly.

You can refer the example project from AndroidTestWithoutSource.

cmoaciopm
  • 2,076
  • 2
  • 22
  • 30
  • how can we match the signature of Application without source code and test APK? – Sushant Somani Apr 12 '19 at 09:13
  • @SushantSomani You can use apksigner in android-sdk($SDK_ROOT/build-tools/28.0.2/apksigner) to resign an apk. – cmoaciopm Apr 12 '19 at 10:02
  • When I'm registering instrumentation in AndroidManifest.xml , I can see some errors. Will your code at github still work? – Sushant Somani Apr 12 '19 at 11:42
  • how to run test APK with the same process as main application APK? – Sushant Somani Apr 16 '19 at 17:06
  • @SushantSomani The test APK always run in the same process as main application APK. The command to run test apk looks like "adb shell am instrument ...". You can get more details from my github sample project or Android official document. – cmoaciopm Apr 17 '19 at 05:16
  • so you mean to say when I'm testing 3rd party APK then the current process for espresso test in Android studio, will run under the same process? – Sushant Somani Apr 17 '19 at 05:19
  • As I'm getting below error: "Intent in process com.xyz.abc resolved to different process com.pqr.str: Intent { act=android.intent.action.MAIN flg=0x14000000 cmp=com.pqr.str/.activities.MainActivity }" – Sushant Somani Apr 17 '19 at 05:32
  • @SushantSomani Please share your project somewhere. It is hard to find the cause via this error message. – cmoaciopm Apr 17 '19 at 06:18
  • I've posted a new question at: https://stackoverflow.com/questions/55721618/intent-resolved-to-different-process-in-espresso-test-for-apk-without-source-co – Sushant Somani Apr 17 '19 at 06:57
3

I am not sure if this is still relevant to you but I will leave my comment for the ages. First some general information:

White-box Testing is simply put - testing an app WITH the source code. It requires programming and understanding of the app architecture when designing the tests

Black-box Testing is testing your app WITHOUT the source code of the app. It again requires some programming, but you design your tests without any knowledge of the architecture.

In your case:

Is it not possible to automation android app using espresso without source code.

As per the upper two definitions - Yes it is possible with a Black-box testing framework.

But I would like to run these automation tests on a different version of the app? Is this possible just by installing the app and running the tests?

Yes this is possible using a black-box app.

However, your choice - Espresso is a white-box testing framework. You have two possible solutions:

  1. Get the source code of the version you want to test and write the tests for the version.
  2. Try a black-box testing framework - I can give you further advice on this if you need
0

As per my knowledge, espresso requires application source code.So it is not possible to automate it with just an apk build.

Chandrashekhar Swami
  • 1,742
  • 23
  • 39
0

as i understand older version of your app doesn't have espresso tests.

Open a commit with different version of app, into androidTest include tests and run assembleAndroidTest Gradle task to make an app which already would have included your tests.

This version of app might be useful for Testdroid platform.

I'm not an expert in this, but I can also suggest you to use monkey tool

Read about it here: http://developer.android.com/tools/help/monkey.html

and if you know a bit Python you can use monkeyrunner for this.

Check: http://developer.android.com/tools/help/monkeyrunner_concepts.html

These two tools will help you a lot to run the test on the different versions of app.

Hope it help

piotrek1543
  • 19,130
  • 7
  • 81
  • 94