在特定的設備上運行gradle的connectedAndroidTest

[英]Running gradle's connectedAndroidTest on a specific device


How do you run connectedAndroidTest on a particular device?

如何在特定設備上運行connectedAndroidTest ?

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.

我們的CI服務器上有許多設備,我似乎找不到任何關於如何針對特定連接設備的文檔。

connectedAndroidTest runs the tests on ALL connected devices currently.

connectedAndroidTest目前在所有連接設備上運行測試。

Thanks.

謝謝。

3 个解决方案

#1


11  

It's not supported. 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:

它不支持。在http://tools.android.com/tech-docs/new build-system/user-guide#TOC-Android-tasks上的connectedCheck文檔明確地指出:

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

運行需要連接設備或模擬器的檢查。它們將在所有連接的設備上並行運行。

There is a feature request for the ability to select individual devices; you can track its progress at https://code.google.com/p/android/issues/detail?id=66129

對於選擇單個設備的能力有一個特性請求;您可以通過https://code.google.com/p/android/issues/detail?id=66129來跟蹤它的進程

#2


4  

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.

我創造了一個“黑客”來做這件事。將此塊放在構建的android部分。然后,您必須將ANDROID_HOME env變量設置為sdk文件夾,並將UNIT_TESTS_DEVICE_ID env變量設置為要運行測試的設備的序列號。

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<com.android.builder.testing.api.DeviceConnector> devices = super.devices;
        List<com.android.builder.testing.api.DeviceConnector> 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.

然后使用任務singleDeviceAndroidTest{Variant}運行測試。僅在1.0版本的gradle插件上測試。

#3


3  

looks like a future release according to this code snippet https://android-review.googlesource.com/#/c/160929/

根據代碼片段https://android-review.googlesource.com/#/c/160929/,看起來像是一個未來的版本


注意!

本站翻译的文章,版权归属于本站,未经许可禁止转摘,转摘请注明本文地址:https://www.itdaan.com/blog/2014/05/30/72a1288c0cd6b39f3185ba355685db62.html



 
粤ICP备14056181号  © 2014-2020 ITdaan.com