Can’t run espresso tests under docker-android container

I am trying to set up Docker-Android to run Espresso tests.

I have used the project under the Readme.md and I am trying to execute the docker command that runs those tests, to achieve that I have changed the following command from the Readme.md:

docker run -it --rm -v $PWD/android-testing/ui/espresso/BasicSample:/root/tmp budtmo/docker-android-x86-8.1 tmp/gradlew build

To adapt it and run the task I need:

docker run -it --rm -v $PWD/BasicSample:/root/BasicSample budtmo/docker-android-x86-8.1 BasicSample/gradlew connectedAndroidTest

As you can see from my previous command I am building the SampleProject under a BindMount so that the project gets added into the container to then execute the gradlew task but all I get is the following gradlew error:

connectedAndroidTest task is not found in root project 'root'

I have cloned that project and run that task on my host machine (from the Android Studio terminal) using the gradlew connectedAndroidTest and if my emulator is not not running I get a:

com.android.builder.testing.api.DeviceException: No connected devices!

Which makes a lot of sense…

And once I start the emulator I can see that the tests are running and the build is successful.

Is there anything else I need to be able to run the Espresso tests under that docker container?

Some help would be very much appreciated.

Thanks a lot!

Source: StackOverflow