Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running gradle's connectedAndroidTest on a specific device

Tags:

How do you run connectedAndroidTest on a particular device?

I would expect something like:

./gradlew connectedAndroidTest -DconnectedAndroidTest.device=XXXX 

We have a number of devices plugged into our CI server and I can't seem to find any documentation on how to target a specific connected device.

connectedAndroidTest runs the tests on ALL connected devices currently.

Thanks.

like image 683
Nick Palmer Avatar asked May 30 '14 17:05

Nick Palmer


People also ask

How to run android test in command line?

To run a test from the command line, run adb shell to start a command line shell on your device or emulator. Inside that shell you can interact with the activity manager using the am command and use its instrument subcommand to run your tests.

How do I run a gradle test in CMD?

You can do gradle -Dtest. single=ClassUnderTestTest test if you want to test single class or use regexp like gradle -Dtest. single=ClassName*Test test you can find more examples of filtering classes for tests under this link.

What is assembleAndroidTest?

assembleAndroidTest is the gradle command to build the second test apk. By default assembleAndroidTest will build the test apk with the debug build type. You can change the build type by adding this to your build.


2 Answers

Use the ANDROID_SERIAL variable

You can do this two ways:

1. Set environment variable

# Set once; all following gradlew commands will use this export ANDROID_SERIAL=1000AB0123456YZ  ./gradlew <...> 

2. "Set" for just a command

ANDROID_SERIAL=1000AB0123456YZ ./gradlew <...> 

If you set/exported ANDROID_SERIAL (method #1), you can use this to override that for a single command.

Note

This works with emulator identifiers (e.g., "emulator-5554"), too.

like image 182
MotohawkSF Avatar answered Sep 30 '22 17:09

MotohawkSF


It was not supported in 2014. The documentation for connectedCheck at http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Android-tasks, which delegates to connectedAndroidTest for these sorts of on-device non-UI-automated tests, explicitly states:

Runs checks that requires a connected device or emulator. They will run on all connected devices in parallel.

There is a feature request (now marked as fixed) for the ability to select individual devices: https://code.google.com/p/android/issues/detail?id=66129

like image 28
Scott Barta Avatar answered Sep 30 '22 19:09

Scott Barta