Xcode4: Running Application Tests From The Command Line in iOS

原文链接:http://www.cnblogs.com/simonshi2012/archive/2012/09/27/2705811.html

From: http://longweekendmobile.com/2011/04/17/xcode4-running-application-tests-from-the-command-line-in-ios/

While researching the “is GHUnit still relevant vis-a-vis Xcode 4” article, I discovered this Carbon Five post by Jonah: Running Xcode 4 unit tests from the command line.

In short, I found a way to run iOS application unit tests from the command line; this article describes that process.

 

Part of the research is about automation – how well GHUnit and/or OCUnit test suites can be automated.

In my book, command line = automation. Last summer I installed Hudson CI on Paul’s Mac Mini and started automated builds. Why not add unit tests to the mix?

Jonah’s post explains how to make a unit test bundle testable from the command line. Unfortunately, and he notes it as well, it only works for logic tests (e.g. no application tests). His approach uses schemes in Xcode 4.

Jonah’s command:

xcodebuild -workspace workspaceName.xcworkspace -schemelogicTestSchemeName -sdk iphonesimulator4.3 -configuration Debug clean build

I’m still not sure I fully understand schemes/workspaces yet, as they are new to Xcode 4, but this is definitely one case where good ol’ targets appear to work better.

By using the target paradigm, we can build the bundle without creating a new scheme. Instead, just use the test bundle’s name as your build target:

xcodebuild -target unitTestBundleTargetName -configuration Debug -sdk iphonesimulator4.3 clean build

This improved upon the first half of his post – removing the need to create a separate scheme. His post ends with a challenge for application tests:

In case it is of any help to other developers struggling with the difference between command line and Xcode builds.

The “Run Script” build phase of a unit test build target just runs… (edit: references some scripts, omitted for brevity)

Hopefully it will prove possible to use these scripts to match the behavior seen when running tests from within Xcode to automatically run application tests.

So, I included an application test in my unit test bundle, and this was the output:

/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/RunPlatformUnitTests:94: warning: Skipping tests; the iPhoneSimulator platform does not currently support application-hosted tests (TEST_HOST set).

Isn’t it supported? We’ve seen it working in Xcode 4. Maybe it really is supported, but Apple hasn’t updated the testing script because they were so busy just trying to get Xcode 4 in a semi-releasable state (highly likely). Or, it hasn’t been “officially” said to work; e.g. they don’t want to support it yet, so they’re not letting us do it.

After snaking through all the script calls, I found the culprit.

Change line 95 of/Developer/Platforms/iPhoneSimulator.platform/Developer/Tools/RunPlatformUnitTestsfrom

Warning ${LINENO} "Skipping tests; the iPhoneSimulator platform does not currently support application-hosted tests (TEST_HOST set)."

to these 2 lines:

export OTHER_TEST_FLAGS="-RegisterForSystemEvents"
RunTestsForApplication "${TEST_HOST}" "${TEST_BUNDLE_PATH}"

The first line of code seems to make event handling work with Springboard (see comments below). The second line of code I stole from/Developer/Tools/RunPlatformUnitTests. Seems like it’s the default behavior for other platforms, just not the simulator SDK.

EDIT: Running Xcode 4.3? You still need to edit this file in this fashion, but do so according to Roger’s guidelines in the comments section below – you need to change the build phase script & make a copy of your script.

After inserting those lines, your tests should run (I’ve included a sample project with the set up to show the code, it is the “navigation based app” template using Core Data).

Also, it’s important to note that the Simulator will not run 2 instances. You’ll need to shut the Simulator if you have it open.

DISCLAIMER:Yes, I’m asking you to change your /Developer directory. You probably should back everything up, blah blah blah, and I don’t want to be blamed if you have to reinstall Xcode 4.

Also, I originally had Core Data as part of the project, but I was getting anNSCocoaErrorDomain error from my application on the console. After I removed Core Data from the project, the problem went away.

Deniz Demir helped me out there – a little Google brought up his post from late March, where he explained his troubles with Core Data and unit testing. Applying his fix inre: the documents directory makes my code work. Glad to see everyone work at the coal face of the problem!

Best of luck!

转载于:https://www.cnblogs.com/simonshi2012/archive/2012/09/27/2705811.html

原文地址:https://blog.csdn.net/weixin_30268921/article/details/97776696

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


在有效期内的苹果开发者账号(类型为个人或者公司账号)。还有一种情况,就是你的Apple ID被添加到公司开发者账号团队里面,这样也是可以的,但是需要叫管理员给你开通相应的账号权限,如下截图:这里可能有些同学会问,苹果开发者账号是什么?如何申请?那么可以看看我的上一篇文章:iOS苹果开发者账号(公司账号)申请流程详解能正常编译打包的iOS工程项目(都不能正常编译谈何出包上架
Appuploader官网--IOS ipa上传发布工具,证书制作工具跨平台版,windows,linux,mac系统都可用 (applicationloader.net)第一步:注册苹果开发者账号,访问以下网址,按照提示注册即可,因为不需要支付688认证苹果开发者,所以没什么好讲的。证书部分:主要是通过工具生成.p12证书文件,后面这个证书要导入mac系统。描述文件:这个文件主要包含了证书,公钥,设备信息等,具体可以百度了解详情。第三步:使用xcode打包导出ipa文件,供其他人内测。..........
苹果在9月13号凌晨(北京时间)发布 iOS 16,该系统的设备可能会因为各种原因,导致功能不可用和UI错乱等问题,我们需要做好适配iOS 16。
计算机图形学--OpenGL递归实现光线追踪
Xcode 14打出来的包在低版本系统运行时会崩溃,报错信息是Library not loaded: /usr/lib/swift/libswiftCoreGraphics.dylib,在苹果开发者论坛搜索报错信息,可以看到会闪退的最高版本是iOS12.1(不敢肯定,毕竟我没测过,不过肯定低于iOS 12.4
iOS16手机开启开发者模式 "developer mode disable"Pod工程中的Bundle target签名报错
【计算机图形学】【实验报告】DDA画线算法、Bresenham中点画线算法、多边形填充算法(附代码)
iOS 16 满载全新的个性化功能、更具深度的智能技术,以及更多无缝的沟通与共享方式,让 iPhone 的体验更进一步。13、隐私权限增强,如通过 UIDevice 获取设备名称时,无法获取用户的信息,只能获取设备对应的名称。
3、回到苹果开发者中心,如下图,点击certificates,点蓝色小加号,就可以开始创建证书,创建证书的时候无论测试还是上传app store打包,都要选ios distribution app store and adhoc,不要选apple和develpment类型的证书。2、如下图,点左边的profiles菜单,点击蓝色加号,创建描述文件,创建过程中会要求我们选择描述文件的类型,假如你想发布app到app store,则选择app store,假如你想真机测试,则选择ad hoc类型。
需要:Unity,IOS平台模块,Xcode,IOS_SDk,MAC电脑,Iphone手机
最近下载安装 xcode 并解压安装,遇到一些问题误以为是错误,记录在此。从百度和谷歌上搜了很多帖子,发现并没有靠谱的 xcode 国内的镜像,这里提供一个可以跳转到官网的下载方式。xcode 不同版本的列表,下载时注意不同 macOs 不同的系统和 Xcode 版本的对应关系。如 要求 及其以上版本。https://xcodereleases.com/注意点击后会跳到官方下载地址,需要登录苹果账号。xcode 文件很大,通常要 10G 以上,下载速度很慢。可以考虑使用 Free Downlo
使用苹果登录作为第三方登录
missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun解决方法
Xcode14 正式版编译报错' does not contain bitcode.You must rebuild it with bitcode enabled (Xcode setting ENABLE_BITCODE), obtain an updated library from the vendor, or disable bitcode for this target. file 'xxx' for architecture arm64解决方案
那应该和升级Xcode 14有关系。但是官方还没有给出解决方案。应该后续会有兼容的cocoapods 新版本。
项目中需要用到Xcode将C++代码输出的Mac版本的DLL文件即DYLIB文件,并能够使用C#代码调用。Unity与 DLL文件 ☀️| 怎样使用VC++生成一个DLL文件并调用!这次来看一下在Mac使用Xcode生成的方法吧!本文介绍了在Mac中怎样使用 Xcode项目使用C++生成 .dylib文件的方法。相对于在Windows中使用AndroidStudio创建动态链接库的方法来说,使用Xcode创建.dylib文件确实简单了很多。