简体   繁体   English

如何设置Jenkins运行android单元测试?

[英]How to setup Jenkins run android unit tests?

I have recently installed Jenkins on my development machine to help me learn how continuous integration/delivery works. 我最近在开发机器上安装了Jenkins,以帮助我了解持续集成/交付的工作方式。

I have a basic Android task setup that will build my app and then report lint, PMD, Checkstyle, Findbugs, and JUnit (business logic) test results. 我有一个基本的Android任务设置,它将构建我的应用程序,然后报告皮棉,PMD,Checkstyle,Findbugs和JUnit(业务逻辑)测试结果。

I would also like it to run android unit tests (those that require an emulator to run), how does one set this up? 我还希望它运行android单元测试(那些需要仿真器才能运行的测试),请问如何设置呢? After I have added 'connectedAndroidTest' to the list of gradle commands to run during the build I get the following output: 将'connectedAndroidTest'添加到要在构建期间运行的gradle命令列表中后,得到以下输出:

17:03:21 :app:connectedDebugAndroidTest FAILED
17:03:21 
17:03:21 FAILURE: Build failed with an exception.
17:03:21 
17:03:21 * What went wrong:
17:03:21 Execution failed for task ':app:connectedDebugAndroidTest'.
17:03:21 > com.android.builder.testing.api.DeviceException: No connected devices!
17:03:21 
17:03:21 * Try:
17:03:21 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
17:03:21 
17:03:21 BUILD FAILED

This is expected, so I tried starting an emulator from Android Studio and running the Jenkins build again, resulting in this error: 这是预期的,因此我尝试从Android Studio启动模拟器并再次运行Jenkins构建,导致此错误:

17:08:54 :app:connectedDebugAndroidTest
17:08:54 05:08:54 E/SplitApkInstaller: Failed to finalize session : INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.zao.testapp.test signatures do not match the previously installed version; ignoring!
17:08:54 Unable to install C:\Program Files (x86)\Jenkins\workspace\testapp\app\build\outputs\apk\app-debug-androidTest.apk
17:08:54 com.android.ddmlib.InstallException: Failed to finalize session : INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.zao.testapp.test signatures do not match the previously installed version; ignoring!
17:08:54    at com.android.ddmlib.SplitApkInstaller.install(SplitApkInstaller.java:92)
17:08:54    at com.android.ddmlib.Device.installPackages(Device.java:904)
17:08:54    at com.android.builder.testing.ConnectedDevice.installPackages(ConnectedDevice.java:136)
17:08:54    at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:134)
17:08:54    at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:49)
17:08:54    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
17:08:54    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
17:08:54    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
17:08:54    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
17:08:54    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
17:08:54    at java.lang.Thread.run(Thread.java:748)
17:08:54 
17:08:54 com.android.builder.testing.ConnectedDevice > runTests[emulator-5554 - 8.0.0] [31mFAILED [0m
17:08:54    com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Failed to finalize session : INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.zao.testapp.test signatures do not match the previously installed version; ignoring!
17:08:54        at com.android.builder.testing.ConnectedDevice.installPackages(ConnectedDevice.java:144)

17:08:54 [no message defined]
17:08:54 com.android.builder.testing.api.DeviceException: com.android.ddmlib.InstallException: Failed to finalize session : INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.zao.testapp.test signatures do not match the previously installed version; ignoring!
17:08:54    at com.android.builder.testing.ConnectedDevice.installPackages(ConnectedDevice.java:144)
17:08:54    at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:134)
17:08:54    at com.android.builder.internal.testing.SimpleTestCallable.call(SimpleTestCallable.java:49)
17:08:54    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
17:08:54    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
17:08:54    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
17:08:54    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
17:08:54    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
17:08:54    at java.lang.Thread.run(Thread.java:748)
17:08:54 Caused by: com.android.ddmlib.InstallException: Failed to finalize session : INSTALL_FAILED_UPDATE_INCOMPATIBLE: Package com.zao.testapp.test signatures do not match the previously installed version; ignoring!
17:08:54    at com.android.ddmlib.SplitApkInstaller.install(SplitApkInstaller.java:92)
17:08:54    at com.android.ddmlib.Device.installPackages(Device.java:904)
17:08:54    at com.android.builder.testing.ConnectedDevice.installPackages(ConnectedDevice.java:136)
17:08:54    ... 8 more
17:08:54 :app:connectedDebugAndroidTest FAILED
17:08:54 
17:08:54 FAILURE: Build failed with an exception.
17:08:54 
17:08:54 * What went wrong:
17:08:54 Execution failed for task ':app:connectedDebugAndroidTest'.
17:08:54 > There were failing tests. See the report at: file:///C:/Program%20Files%20(x86)/Jenkins/workspace/testapp/app/build/reports/androidTests/connected/index.html
17:08:54 
17:08:54 * Try:
17:08:54 Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
17:08:54 
17:08:54 BUILD FAILED

I also tried setting up an emulator through the task setup. 我还尝试通过任务设置来设置仿真器。 There is an option to "Run an Android emulator during build" that I have checked. 我已经选中了“在构建过程中运行Android模拟器”选项。

The option to run an existing emulator doesn't work for me - I give it the AVD name from the emulator I created in Android Studio, in my case "Nexus_5X_API_26" and I get the following error when I build: 运行现有模拟器的选项对我不起作用-我将其命名为我在Android Studio中创建的模拟器的AVD名称,在我的情况下为“ Nexus_5X_API_26”,并且在构建时出现以下错误:

17:26:07 FATAL: C:\Windows\system32\config\systemprofile\.android\avd\Nexus_5X_API_26.ini (The system cannot find the path specified)
17:26:07 java.io.FileNotFoundException: C:\Windows\system32\config\systemprofile\.android\avd\Nexus_5X_API_26.ini (The system cannot find the path specified)

Which makes sense since my emulator is in C:\\Users\\Zach.android\\avd\\ . 因为我的模拟器在C:\\ Users \\ Zach.android \\ avd \\中,所以这很有意义。

I also tried to run an emulator with properties that I specify in the config, using the following values: 我还尝试使用以下值运行具有在配置中指定的属性的仿真器:

Android OS version: android-26
Screen density: 420
Screen resolution: 1080x1920
Device locale: en_US
SD card size: <empty>
Target ABI: x86
Emulator name suffix: <empty>

And I get the following output: 我得到以下输出:

17:31:51 $ D:\Android\sdk/tools/android.bat list target
17:31:52 [android] The configured Android platform needs to be installed: android-26
17:31:52 $ D:\Android\sdk/tools/android.bat list target
17:31:53 $ D:\Android\sdk/tools/android.bat list target
17:31:54 [android] Installing the 'sys-img-x86-android-26' SDK component(s)...
17:31:54 $ D:\Android\sdk/tools/android.bat update sdk -u -a -t sys-img-x86-android-26
17:31:54 **************************************************************************
17:31:54 The "android" command is deprecated.
17:31:54 For manual SDK, AVD, and project management, please use Android Studio.
17:31:54 For command-line tools, use tools\bin\sdkmanager.bat
17:31:54 and tools\bin\avdmanager.bat
17:31:54 **************************************************************************
17:31:54 
17:31:54 "android" SDK commands can be translated to sdkmanager commands on a best-effort basis.
17:31:54 (This prompt can be suppressed with the --use-sdk-wrapper commend-line argument
17:31:54 or by setting the USE_SDK_WRAPPER environment variable)

Which causes Jenkins to hang forever with a busy indicator at the last line of the console output view. 这会导致Jenkins在控制台输出视图的最后一行上因忙碌指示器而永久挂起。 I am forced to abort the build and restart Jenkins at this point in order to have builds work again. 我被迫中止构建并在此时重启Jenkins,以使构建再次起作用。

So, what am I missing here? 那么,我在这里想念什么? Why is this so difficult for me! 为什么这对我来说如此困难! Anyone know how to accomplish running Android unit tests -> get a simulator to kick off for a build on Jenkins? 任何人都知道如何完成Android单元测试的运行->让模拟器开始在Jenkins上构建吗?

EDIT : I updated Jenkins to run as 'me' rather than the local system account and that allowed me to (try to) use an existing emulator rather than complain about not being able to find it. 编辑 :我将Jenkins更新为以“我”的身份运行,而不是本地系统帐户,这使我能够(尝试)使用现有的模拟器,而不是抱怨找不到它。 However, I now get this error when trying to start the emulator: 但是,现在尝试启动模拟器时出现此错误:

00:28:11 $ D:\Android\sdk/tools/android.bat list target
00:28:12 [android] Using Android SDK: D:\Android\sdk
00:28:12 $ D:\Android\sdk/platform-tools/adb.exe start-server
00:28:16 * daemon not running. starting it now at tcp:5847 *
00:28:16 * daemon started successfully *
00:28:16 $ D:\Android\sdk/platform-tools/adb.exe start-server
00:28:16 [android] Starting Android emulator
00:28:16 $ D:\Android\sdk/tools/emulator.exe -engine classic -ports 5688,5689 -report-console tcp:5831,max=60 -avd Nexus_5X_API_26 -no-snapshot-load -no-snapshot-save -no-window
00:28:16 PANIC: Missing emulator engine program for 'x86' CPU.
00:29:21 [android] Emulator did not appear to start; giving up
00:29:21 [android] Stopping Android emulator
00:29:22 $ D:\Android\sdk/platform-tools/adb.exe kill-server

So I guess this is the number one question for now, any thoughts? 所以我想是目前的头号问题,有什么想法吗?

I was able to get this working by adding the "-engine auto" emulator option. 通过添加“ -engine auto”仿真器选项,我能够使它正常工作。

I looked at this Jenkins issue to help solve this: https://issues.jenkins-ci.org/browse/JENKINS-43557 我查看了这个詹金斯问题,以帮助解决此问题: https : //issues.jenkins-ci.org/browse/JENKINS-43557

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM