2

The current code baseline / application I am working on abstracts away much of the Android framework. The feature I am writing is opened as a plugin within the Android application. I thus do not have access to the Activity of the main application and have used the UI Automator to start the application and the plugin (this part works fine).

Is it possible to get Espresso to tie into the application at this point so I can test to behavior / views? When I attempt to run Espresso commands at this point I get the following error: java.lang.RuntimeException:

No activities found. Did you forget to launch the activity by calling getActivity() or startActivitySync or similar? at androidx.test.espresso.base.RootViewPicker.waitForAtLeastOneActivityToBeResumed(RootViewPicker.java:176)

nbonbon
  • 1,660
  • 3
  • 18
  • 27
  • Needs more info and clarification, what is the code being called? What exactly is the plugin (a java library, gradle plugin, etc...)? Structure of your project would be helpful as well along with `build.gradle` files or just sample of the project. – ahasbini Oct 02 '19 at 16:22
  • @ahasbini the 'plugin' verbiage is the verbiage the Android application we are writing code foe uses. The plugin itself (our app) is launched from inside of the Android application. The structure and build.gradle cannot be supplied because of the nature of the work. This question is meant to be generic and at a high level. I simply need to know if it is possible to run espresso code against an application that espresso did not start itself. – nbonbon Oct 02 '19 at 18:26
  • Based on this: https://stackoverflow.com/a/41327515/2949966, it could work if the test apk is signed with the same signature of app apk. Is that what you're looking for? – ahasbini Oct 03 '19 at 10:44
  • I've stumbled upon `apply plugin: 'com.android.test'`. It's possible to use it if the app code is accessible for referencing and using the same starting application id. This could mean that it allows to have the test code separate from the app code but still be able to run tests on the app. I honestly haven't tried it but hoping if it suites you in some way. Here's a link for more info: https://developer.android.com/studio/test#use_separate_test_modules_for_instrumented_tests – ahasbini Oct 07 '19 at 23:15
  • for testing isolation, you should create a sample app to test your plugin and not using "the real application".It's not recommended method, you could start the activity using implicit intent for your "main application" using https://developer.android.com/training/testing/espresso/intents – Anis BEN NSIR Oct 09 '19 at 13:19
  • @nbonbon did you ever figure how to do this? I'm in the same exact situation as you. – rominoushana Jun 02 '20 at 00:48
  • @rominoushana I did not. We ended up just using UIAutomator for the testing. Which is a bit more clunky and less versatile. Not what we wanted. – nbonbon Sep 01 '20 at 19:27

0 Answers0