Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android automation using espresso without the app source code

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

like image 409
Virus Avatar asked Feb 05 '16 06:02

Virus


People also ask

Which is better espresso or Appium?

Overall, Espresso is much more stable than Appium for automated Android UI testing. In addition to that, the execution of test scripts is much faster.

Does Appium use espresso?

Appium currently has support for the Espresso automation technology via its own Espresso driver. This driver works by kicking off an Espresso run on a device, with our own automation server as part of the Espresso test APK.

Is Espresso only for Android?

Espresso is only for testing Android apps. If you need to test iOS apps or other platforms, you are out of luck. You have to have access to the app's source code in order to test with Espresso.

What is the use of espresso in Android?

Espresso is a testing framework for Android to make it easy to write reliable user interface tests.


2 Answers

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.

like image 76
cmoaciopm Avatar answered Oct 19 '22 01:10

cmoaciopm


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
like image 37
George Spasov Avatar answered Oct 19 '22 02:10

George Spasov