How do you run connectedAndroidTest on a particular device?
I would expect something like:
./gradlew connectedAndroidTest -DconnectedAnd
I created an "hack" to be able to do it.. put this block in the android section of your build.gradle, and then you have to set the ANDROID_HOME env variable to the sdk folder, and the UNIT_TESTS_DEVICE_ID env variable with the serial number of the device on which you want to run tests on.
deviceProvider(new com.android.builder.testing.ConnectedDeviceProvider(file(System.getenv("ANDROID_HOME") + File.separator + "platform-tools" + File.separator + "adb")) {
public String getName() {
return "singleDevice"
}
public List extends com.android.builder.testing.api.DeviceConnector> getDevices() {
List devices = super.devices;
List toReturn = new ArrayList<>();
String deviceSerialNum = System.getenv("UNIT_TESTS_DEVICE_ID");
devices.each {
if (it.getSerialNumber().equals(deviceSerialNum)) toReturn.add(it);
}
if (toReturn.isEmpty()) {
throw new RuntimeException("Device for unit tests not found!");
}
return toReturn;
}
})
Then you use the task singleDeviceAndroidTest{Variant} to run the tests. Tested only on gradle plugin version 1.0.0.