OCUnit测试从命令行失败,但在使用钥匙串服务时在Xcode中工作 [英] OCUnit tests fail from the command line but work in Xcode when using Keychain Services

查看:221
本文介绍了OCUnit测试从命令行失败,但在使用钥匙串服务时在Xcode中工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用SFHFKeychainUtils在我的应用程序使用钥匙串服务。我写了一些OCUnit测试来验证这个代码的功能。一切工作正常,当我在iOS模拟器或我的设备上从Xcode运行单元测试。但是现在我试图设置CI服务器,测试失败,当它通过命令行运行时出现错误代码-25291。查看苹果的文档告诉我:没有信任结果可用(errSecNotAvailable)。我已经链接Security.framework到我的单元测试项目,它似乎是从我在网上阅读,这是我应该需要得到这个工作。这是我在控制台中调用的命令:

I'm using SFHFKeychainUtils to use Keychain Services in my app. I've written some OCUnit tests that verify the funcionality of this code. Everything works fine when I run the unit tests from Xcode on the iOS simulator or my device. However now I'm trying to set up a CI server and the test is failing when it is run via the command line with error code -25291. Looking that up on Apple's documentation tells me: No trust results are available (errSecNotAvailable). I've linked the Security.framework to my unit test project, it seems like from what I have read on the web this is all I should need to get this working. Here is the command I am invoking in the console:

/ usr / bin / xcodebuild -target [Test_Target] -sdk / Applications / Xcode。 app / Contents / Developer / Platforms / iPhoneSimulator.platform / Developer / SDKs / iPhoneSimulator5.1.sdk / -configuration调试

推荐答案

我有什么经验或建议,让单元测试和Keychain服务从命令行一起玩?遇到同样的问题,我的解决方案是确保模拟器在开始任何测试之前运行。我在Xcode的运行脚本构建阶段使用AppleScript,在CI服务器上基本上是相同的事情。这是打开模拟器的shell脚本:

I ran into the same issue, and the solution for me was to make sure the simulator was running before starting any test. I did that using AppleScript in a Run Script build phase in Xcode, and essentially the same thing on the CI server. Here is the shell script that will open the simulator:

exec osascript<< EOF

告诉应用程式iOS模拟器

激活

结束告诉

导致这种情况的安全/钥匙串服务问题显然是一个已知问题,虽然我还没有跟踪它的雷达。如果您使用Jenkins,请将上述脚本放在Xcode构建阶段之前的执行Shell阶段。如果你通过Xcode本身控制它,把它放在运行脚本构建阶段之前RunUnitTests运行脚本构建阶段。
希望解决您的问题!

The security/keychain services issue that causes this is apparently a known issue, though I don't yet have the radar that tracks it. If you're using Jenkins, put the above script in a Execute Shell phase before your Xcode build phase. If you're controlling this through Xcode itself, put it in a Run Script build phase before the RunUnitTests Run Script build phase. Hope that solves your issue!

这篇关于OCUnit测试从命令行失败,但在使用钥匙串服务时在Xcode中工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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