I am trying to automate some UI of my Android application(I do not have source code so I am using the APK file) .
I have gone through tutorial provided here and also
To use espresso you need to know something about the UI elements themselves (like id and type). When you don't have the source code you can use the "uiautomatorviewer" tool which is part of the Android SDK.
http://developer.android.com/tools/testing-support-library/index.html#uia-viewer
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:
There is an instrumentation registered in AndroidManifest.xml, which will be registered to Android system once test apk is installed
The test apk must be signed using the same signature with the application apk, in order to run automation test
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:
You can easily control the activity lifecycle using class ActivityTestRule.
You can test application defined classes easily.
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:
You have to use Class.forName to load the entrance activity and launch it
You have to use Java reflection to test application defined classes
You have to use literal information to find UI widgets, because you don't have the id of the UI widgets
I think it's due to the above disadvantages, which makes Google prefer to building Espresso test together with source code.
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.
I have gone through tutorial provided here and also some tutorial available at Google but all of them require source code.
That is because Espresso is part of instrumentation testing, and it requires source code.
Other tools — UI Automator and monkeyrunner, for example — do not require source code.
As Espresso is more backward compatible with previous version of Android and also have performance advantage over UIAutomator that why I want to use Espresso
Then talk to the developer of the app and arrange with that person to test the app, with full source code access.