I'm working to setup my test infrastructure on an Android app. I'm using Android Studio, gradle, Espresso, MonkeyRunner, emulators, and real devices. I run AndroidTest using gradlew connectedAndroidTest
.
In setting up proper test fixtures, I'm interested in having a background process that is started up before the tests start, then torn down when they're done. Is there a way to do that with gradle, etc?
Specifically what I'm trying to do right now is do a screen capture with MonkeyRunner in the middle of an Espresso test. Spinning up MonkeyRunner in the middle of the test is time-consuming so having it running as a daemon could speed the test up. (I understand the whole thing is a bit hokey, but ultimately I'm looking for an efficient way to do screen capture compares. If it was built into the Java libs in a more native way I'd do it that way). In this case, the MonkeyRunner process would spin up and connect to the device. The AndroidTest process would then spin up, run a test which may signal the MonkeyRunner process to take a snapshot and compare it to a reference, then AndroidTest continues to the next test which may do the same thing.
Other things the separate process pattern might enable would be external comms, or other things I may need for a test fixture.