Unit testing xcodebuild无头运行测试?

Unit testing xcodebuild无头运行测试?,unit-testing,xcodebuild,headless,Unit Testing,Xcodebuild,Headless,我们现在都知道,在iOS上运行测试的唯一方法是使用模拟器。我的问题是,我们正在运行jenkins,而iOS构建是在从机上运行的(通过SSH),因此运行xcodebuild无法启动模拟器(因为它是无头运行的)。我在某个地方读到过,应该可以让它与SimLauncher(gem sim_launcher)一起工作。但是我找不到任何关于如何使用xcodebuild设置的信息。欢迎使用任何指针。Headless和xcodebuild不能很好地混合使用。请考虑这个备选方案: 您可以将从属节点配置为通过jnl

我们现在都知道,在iOS上运行测试的唯一方法是使用模拟器。我的问题是,我们正在运行jenkins,而iOS构建是在从机上运行的(通过SSH),因此运行xcodebuild无法启动模拟器(因为它是无头运行的)。我在某个地方读到过,应该可以让它与SimLauncher(gem sim_launcher)一起工作。但是我找不到任何关于如何使用xcodebuild设置的信息。欢迎使用任何指针。

Headless和xcodebuild不能很好地混合使用。请考虑这个备选方案:

您可以将从属节点配置为通过jnlp(webstart)启动。我使用带有
.command
扩展名的bash脚本作为登录项(系统首选项->用户->登录项),其内容如下:

#!/bin/bash

slave_url="https://gardner.company.com/jenkins/jnlpJars/slave.jar"

max_attempts=40 # ten minutes
echo "Waiting to try again. curl returneed $rc"
curl -fO "${slave_url}" >>slave.log
rc=$?
if [ $rc -ne 0 -a $max_attempts -gt 0 ]; then
  echo "Waiting to try again. curl returneed $rc"
  sleep 5
  curl -fO "${slave_url}" >>slave.log
  rc=$?
  if [ $rc -eq 0 ]; then
    zip -T slave.jar
    rc=$?
  fi
  let max_attempts-=1
fi

# Simulator
java -jar slave.jar -jnlpUrl https://gardner.company.com/jenkins/computer/buildmachine/slave-agent.jnlp -secret YOUR_SECRET_KEY
生成用户设置为自动登录。通过执行以下命令,可以查看slave.jar应用程序的参数:

gardner:~ buildmachine$ java -jar slave.jar --help
"--help" is not a valid option
java -jar slave.jar [options...]
 -auth user:pass                 : If your Jenkins is security-enabled, specify
                                   a valid user name and password.
 -connectTo HOST:PORT            : make a TCP connection to the given host and
                                   port, then start communication.
 -cp (-classpath) PATH           : add the given classpath elements to the
                                   system classloader.
 -jar-cache DIR                  : Cache directory that stores jar files sent
                                   from the master
 -jnlpCredentials USER:PASSWORD  : HTTP BASIC AUTH header to pass in for making
                                   HTTP requests.
 -jnlpUrl URL                    : instead of talking to the master via
                                   stdin/stdout, emulate a JNLP client by
                                   making a TCP connection to the master.
                                   Connection parameters are obtained by
                                   parsing the JNLP file.
 -noReconnect                    : Doesn't try to reconnect when a communication
                                   fail, and exit instead
 -proxyCredentials USER:PASSWORD : HTTP BASIC AUTH header to pass in for making
                                   HTTP authenticated proxy requests.
 -secret HEX_SECRET              : Slave connection secret to use instead of
                                   -jnlpCredentials.
 -slaveLog FILE                  : create local slave error log
 -tcp FILE                       : instead of talking to the master via
                                   stdin/stdout, listens to a random local
                                   port, write that port number to the given
                                   file, then wait for the master to connect to
                                   that port.
 -text                           : encode communication with the master with
                                   base64. Useful for running slave over 8-bit
                                   unsafe protocol like telnet

gardner:~ buildmachine$ 

有关OSX从机以及如何启动主机的讨论,请参见Jenkins的错误:

Erik-我最后做了以下几项:

基本上:

第一个问题是,您必须让运行构建的用户也登录到Mac构建机器上的控制台。它需要能够弹出模拟器,如果没有用户登录,它将失败——因为如果没有显示器,它无法完全无头地完成这项工作

其次,XCode开发工具需要提升权限才能执行单元测试上的所有任务。有时您可能会错过它,但如果没有这些,模拟器将给您一个永远不会清除的身份验证提示

第一个解决方案(在Mavericks上)是运行:

sudo security authorizationdb write system.privilege.taskport allow
这将消除其中一类身份验证弹出窗口。您还需要运行:

sudo DevToolsSecurity --enable
根据此工具的苹果手册页:

在普通用户系统上,在给定的登录会话中 任何此类Apple代码签名调试器或性能分析工具都是 用于检查用户的一个进程,用户将被查询 用于授权的管理员密码。开发工具安全工具 更改授权策略,以便 管理员组或_开发者组都不需要输入 使用Apple代码签名调试器或 性能分析工具


唯一的问题是,一旦我升级到Xcode 6,这些相同的东西似乎就被破坏了。回到绘图板上……

嗨,加德纳,我会在有时间的时候尝试这种方法,并批准它是否有效:)@Erik那么这个答案对你有用吗?我将要设置类似的东西。我们没有让它工作,所以我们设置jenkins在windows中运行manager@Erik你能详细说明一下你的设置吗?