如何让Xcode 5在Jenkins奴隶上运行iOS单元测试? [英] How can I get Xcode 5 to run iOS unit tests on a Jenkins slave?

查看:96
本文介绍了如何让Xcode 5在Jenkins奴隶上运行iOS单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们一直在使用Jenkins和Xcode插件来运行iOS应用程序的持续集成,包括自动执行和单元测试报告。这在使用Jenkins的Linux机器和运行Xcode 4.6.3的Mac从机上运行良好。

We've been using Jenkins with the Xcode plugin to run continuous integration of our iOS applications including automatic execution and reporting of the unit tests. This worked well using Jenkins on a Linux machine and a Mac slave running Xcode 4.6.3.

现在我们正在寻求将设置更新为Xcode 5以支持目标iOS 7并且遇到了以下问题。

Now we are looking to update the setup to Xcode 5 to support targetting iOS 7 and have run into the following problems.

首先,单元测试根本不会运行,因为我们使用了Xcode 4中不再支持Xcode 4的RunUnitTests脚本5.我按照Xcode的建议,通过使用单元测试目标的适当方案设置工作区来解决这个问题。

First, the unit tests would not run at all because we were using the RunUnitTests script from Xcode 4 that is no longer supported in Xcode 5. I addressed this, as recommended by Xcode, by setting up the workspace with an appropriate scheme with the unit test target.

然后我配置了Jenkins的Xcode步骤自定义xcodebuild参数设置为 test -destination platform = $ {DESTINATION_PLATFORM},name = $ {DESTINATION_NAME},OS = $ {DESTINATION_OS} 以使其运行单元测试。

I then configured the Xcode step of the Jenkins job with custom xcodebuild arguments set to test -destination platform=${DESTINATION_PLATFORM},name=${DESTINATION_NAME},OS=${DESTINATION_OS} to get it to run the unit tests.

如果我运行xcodebuild命令行,Jenkins的Xcode插件在我自己的机器上的Terminal中运行,则单元测试会运行,但是当Jenkins作业运行时,尝试运行单元测试时,它会失败或挂起。

If I run the xcodebuild command line that the Xcode plugin for Jenkins runs in Terminal on my own machine, the unit tests run, but when the Jenkins job runs, it either fails or hangs when trying to run the unit tests.

我怀疑这是因为使用Xcode 5和测试buildaction而不是RunUnitTests脚本,单元测试现在在iOS模拟器中运行,需要交互式会话,而Jenkins从属进程是从Jenkins master(Linux)运行SSH。如果我使用Jenkins用于SSH的帐户登录到奴隶机器,我可以看到iOS模拟器在单元测试运行时启动,但测试似乎没有运行且作业挂起。如果我没有登录到奴隶机器,Jenkins作业无法运行单元测试。

I suspect this is because with Xcode 5 and the test buildaction instead of RunUnitTests script, unit tests now run in the iOS Simulator which requires an interactive session, and the Jenkins slave process is being run over SSH from the Jenkins master (Linux). If I am logged into the slave machine with the account Jenkins uses for SSH, I can see that the iOS Simulator launches when the unit tests are supposed to run, but the tests don't appear to run and the job hangs. If I am not logged into the slave machine, the Jenkins job fails to run the unit tests.

有没有办法让iOS单元测试在Jenkins上运行通过SSH进行奴隶,如果没有,当项目必须使用Xcode 5构建时,如何保持自动执行单元测试的任何建议?

Is there any way to get the iOS unit tests to run on a Jenkins slave over SSH, and if not, any suggestions on how to keep automating the execution of the unit tests when the project must be built with Xcode 5?

推荐答案

基于 coffeebreaks '回答,我提出了一个完整的解决方案。

Based on coffeebreaks' answer, I've come up with a full solution.

首先,Mac奴隶无法使用SSH启动,必须​​是使用交互式会话手动启动,然后始终保持登录状态。在我的情况下,奴隶实际上是无头的,所以这是一个进一步的复杂化。

First of all, the Mac slave cannot be launched with SSH and must be launched manually using an interactive session and then left logged in at all times. In my situation, the slave is actually headless, so this is a further complication.

以下是我用来使这一切全部运作的步骤。

Here are the steps I used to get this all operational.


  1. 在配置了唯一标签的Jenkins主机上创建一个新的从节点(我选择xcode-unittests)并将启动方法设置为启动从机代理通过Java Web Start)。

  1. Create a new slave node on the Jenkins master configured with a unique label (I chose "xcode-unittests") and launch method set to "Launch slave agents via Java Web Start).

通过屏幕共享(VNC)登录到Mac从属设备并启动从属代理。在我的情况下,我无法获得从浏览器启动的奴隶,可能是因为我的浏览器没有运行applet所需的Java插件。因此我使用了命令行 javaws http:// {jenkins-host} / computer / {slave-name} /slave-agent.jnlp 。为了使这一点更加健壮,我将此命令配置为每次我以交互方式登录到机器时自动运行,在系统偏好设置,用户和用户下。组,登录项。

Login via screen sharing (VNC) to the Mac slave and start the slave agent. In my case, I could not get the slave to launch from the browser, probably because my browser did not have the necessary Java plug-in for running applets. I therefore used the command line javaws http://{jenkins-host}/computer/{slave-name}/slave-agent.jnlp. To make this a bit more robust, I configured this command to automatically run every time I login to the machine interactively, under System Preferences, Users & Groups, Login Items.

退出屏幕共享而不退出Mac从站。这个k尽管没有人真正使用机器,但是运行奴隶代理的交互式会话仍然存在。

Quit Screen Sharing without logging out of the Mac slave. This keeps the interactive session running the slave agent alive, even though nobody is actually using the machine.

为了单元测试在没有提示用户的情况下运行,我还必须在Mac slave上运行 sudo DevToolsSecurity -enable 。这允许Xcode与iOS模拟器进行交互,而无需每次都以交互方式请求许可。

In order for the unit tests to run without prompting a user, I also had to run sudo DevToolsSecurity -enable on the Mac slave. This allows Xcode to interact with the iOS Simulator without interactively asking for permission to do so each time.

如果从机重启,有人必须登录到Mac奴隶让奴隶代理再次运行出于这个原因,我也让我的基于SSH的奴隶也活跃了。我将我的Jenkins工作拆分为单独的工作,用于构建应用程序和运行单元测试。用于构建应用程序的作业配置为在基于SSH的从属设备上运行,并且用于运行单元测试的作业配置为在上述交互式从属节点上运行。这样,如果交互式从属设备发生故障,则只会影响单元测试,而不会影响产品构建。

If the slave machine is ever rebooted, someone must login to the Mac slave to get the slave agent to run again. For that reason, I also left my SSH-based slave active as well. I split my Jenkins jobs into separate jobs for building the apps and running the unit tests. The jobs for building the apps are configured to run on the SSH-based slave, and the jobs for running the unit tests are configured to run on the interactive slave node described above. That way, if the interactive slave goes down, only the unit tests are affected, not the product builds.

这篇关于如何让Xcode 5在Jenkins奴隶上运行iOS单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆