xctool工具

来源:互联网 发布:java写大怪游戏 编辑:程序博客网 时间:2024/05/16 01:03

xctool

【1】xctool的特性:

原文:http://www.infoq.com/cn/news/2013/05/Facebook-buck-xctool-build

xctool是Facebook最近开源的另一种构建工具,它用于构建iOS应用程序。xctool替换了xcodebuild,具有以下特性:

  • 能够作为Xcode.app运行相同的测试
  • 构建输出和测试结果都是JSON格式的,使得我们不需要解析输出
  • xctool只有在发现错误的时候才打印消息,而xcodebuild对每个源文件都会打印。

我们想要知道为什么Facebook基于xcodebuild构建了另一种工具,所以采访了xctool的提交者Fred Potter,询问他为什么这个工具更好一些:

xctool的最大好处在于,它可以从命令行构建和运行单元测试,这和Xcode.app从图形化界面上达到一样的效果。如果你为iOS设置了持续集成系统,那么这就非常重要了。你想要能够自动化运行测试,那些测试与你的开发人员在本地计算机上运行的完全相同,而xcodebuild不会用和Xcode.app相同的方式来构建和运行测试。在Xcode 4中,苹果把单元测试集成到了Xcode中——与“构建”和“运行”一起,有一个新的“测试”动作;使用Xcode scheme,你可以选择启用或者禁用哪些单元测试;如果你依赖于iOS模拟器(也就是应用程序测试)来编写测试,那么Xcode会自动载入模拟器并运行测试。这些都是很大的改进,但看起来苹果并没有把这些改进融入到xcodebuild中,那使得自动化构建和测试非常困难。

另一个重大的问题是构建和测试失败的报告。使用xcodebuild,你会得到大量文本输出,其中包含编译命令、编译错误和警告以及OCUnit的测试输出。如果你想要自动确定哪个组件编译失败,或者哪个单元测试失败,那么你就需要编写自己的正则表达式解析器,那也是我们和其他iOS社区中的人一直在做的工作。那会有效果,但实在很麻烦。有了xctool,我们会让xcodebuild和OCUnit测试运行器把构建输出和测试结果作为JSON对象的结构化流输出。 这让我们可以很容易地以需要的形式来显示构建和测试结果。例如,我们创建了一个报表,以吸引人的、带有颜色的输出形式来显示结果(https://fpotter_public.s3.amazonaws.com/xctool-uicatalog.gif)。 还有人使用这来把测试结果输出为JUnit XML,那在流行的Jenkins构建系统中会显示得很好。

所以,我们最初创建xctool只是为了持续集成系统,但很多开发者最后都在本地计算机上使用它。如果你想要为运行测试拥有命令行的工作流,它会非常方便。

【2】xctool的安装

brew install xctool

【3】xctool的使用

参见:https://github.com/facebook/xctool/blob/master/README.md

1】编译

1>>If you use workspaces and schemes:

path/to/xctool.sh \  -workspace YourWorkspace.xcworkspace \  -scheme YourScheme \  build

2>>If you use projects and schemes:

path/to/xctool.sh \  -project YourProject.xcodeproj \  -scheme YourScheme \  build

2】执行单元测试

1>>To build and run all tests in your scheme, you would use:

path/to/xctool.sh \  -workspace YourWorkspace.xcworkspace \  -scheme YourScheme \  test

2>>To build and run just the tests in a specific target, use the -only option:

path/to/xctool.sh \  -workspace YourWorkspace.xcworkspace \  -scheme YourScheme \  test -only SomeTestTarget

3>>You can go further and just run a specific test class:

path/to/xctool.sh \  -workspace YourWorkspace.xcworkspace \  -scheme YourScheme \  test -only SomeTestTarget:SomeTestClass

4>>Or, even further and run just a single test method:

path/to/xctool.sh \  -workspace YourWorkspace.xcworkspace \  -scheme YourScheme \  test -only SomeTestTarget:SomeTestClass/testSomeMethod

5>>You can also specify prefix matching for classes or test methods:

path/to/xctool.sh \  -workspace YourWorkspace.xcworkspace \  -scheme YourScheme \  test -only SomeTestTarget:SomeTestClassPrefix*,SomeTestClass/testSomeMethodPrefix*

6>>You can also run tests against a different SDK:

path/to/xctool.sh \  -workspace YourWorkspace.xcworkspace \  -scheme YourScheme \  test -test-sdk iphonesimulator5.1

【4】使用xctool中常见的问题

【问题1】执行build时,报错:No matching provisioning profiles found



解决方法:

A.修改BuildSetting中的codeSign,如:


B.执行build命令时,指定编译证书,如:

xctool -project CALayerAndUiView.xcodeproj -scheme CALayerAndUiView -configuration Debug CODE_SIGN_IDENTITY="iPhone Developer: XX" 


【问题2】执行build时,报错:

 error: Launch screens may not use instances of IBUIStoryboardEntryPointIndicator


解决方法:

Delete Your file LaunchScreen.StoryBoard, and then clear "LaunchScreen" in Lauch Screen File as photo. Done. Or you can add file LauchScreen.xib to your project, and then chose it in Launch Screen File as photo 


详见:http://stackoverflow.com/questions/32444733/launch-screen-illegal-configuration-xcode-6-4


【问题3】执行clean命令时,报错:

target specifies product type 'com.apple.product-type.bundle.ui-testing', but there's no such product type for the 'iphoneos' platform

如:



解决方案:

<code><span class="str"><span style="font-family:SimSun;font-size:14px;">1.定位到自己程序的文件夹2.选中后缀是xcodeproj文件,右键,显示包内容3.找到后缀是pbxproj的文件,右键,打开。4.搜索所有的 <code>com.apple.product-type.bundle.ocunit-test</code> , 并且用 <code>com.apple.product-type.bundle</code>替换之</span></span></code>

详见:http://blog.csdn.net/kid_devil/article/details/40143725


【问题4】执行test命令时,报错:fatal error: 'XCTest/XCTest.h' file not found


解决方案:

选择targets,在buildSetting中设framworks search paths的值为: $(PLATFORM_DIR)/Developer/Library/Frameworks


详见:http://stackoverflow.com/questions/24275470/xctest-xctest-h-not-found-on-old-projects-built-in-xcode-6


【问题5】执行test命令时,报错:

use of undeclared identifier 'XCUIApplication'

    [[[XCUIApplication alloc] init] launch]


解决方案:把[[[XCUIApplication alloc] init] launch];注释掉

详见:http://www.jianshu.com/p/7fd9175e6055


【问题6】执行test命令,报错:

'Bundle's executable code doesn't support nor i386, nor x86_64 CPU types

如:


解决方案:命令中指定以模拟器执行。报错中提示运行时只执行i386 或者x86_64,此均为模拟器系统。

如:

xctool -project CALayerAndUiView.xcodeproj -scheme CALayerAndUiView -configuration Debug CODE_SIGN_IDENTITY="iPhone Developer: XX" -sdk iphonesimulator test


详见: https://github.com/facebook/xctool/issues/531





0 0
原创粉丝点击