使用命令行工具运行Xcode 7 UI Tests
原文:Run Xcode 7 UI Tests from the command line
苹果在Xcode 7中引入了一项新技术UI Tests,允许开发者使用Swift或Objective C代码来进行UI测试。直到现在一个可行的方法是使用UI Automation。通过UI Tests,可使用Xcode适当调试问题以及使用Swift或Objective C而无需处理JavaScript代码。
首先为UI Tests创建一个新的target:
在测试分区下,选中Cocoa Touch UI Testing Bundle:
现在打开Project UI Tests文件夹中最新创建的Project_UI_Tests.swift文件。在底部你会有一个名为testExample的空方法。注意看图中的光标,并点击底部红色的记录按钮。
这样就会打开你的app。现在你可以四处点击下,并与你的应用程序进行交互。完成后,再次点击红色录制按钮。
生成的代码类似下边的记录。我已经在生成的代码行之间添加了几个示例XCTAsserts。在Xcode中使用CMD + U即可运行你的应用程序,并且是同时运行单元测试和UI Tests。
现在你已经可以使用CLI运行测试了,无需进一步的调整,不过我们想让UI Tests在一个单独的scheme中,点击scheme并选中New Scheme:
选中最新创建的UI Test target并确认。
如果你计划在CI-server上运行测试,请确保最新创建的scheme已经启用了Shared选项。点击scheme并选择Manage Schemes来打开会话。
从CLI打开测
1
2
3
4
5
|
xcodebuild -workspace App.xcworkspace \ -scheme "SchemeName" \ -sdk iphonesimulator \ -destination 'platform=iOS Simulator,name=iPhone 6,OS=9.0' test |
明确所用Xcode的版本非常重要,我们使用的是最新的测试版本:
1
|
export DEVELOPER_DIR="/Applications/Xcode-beta.app" |
你甚至可以将测试版作为你新的默认运行版本:
1
|
sudo xcode-select --switch "/Applications/Xcode-beta.app" |
UI测试运行时终端输出示例:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
Test Suite 'All tests' started at 2015-06-18 14:48:42.601 Test Suite 'TempCam UI Tests.xctest' started at 2015-06-18 14:48:42.602 Test Suite 'TempCam_UI_Tests' started at 2015-06-18 14:48:42.602 Test Case '-[TempCam_UI_Tests.TempCam_UI_Tests testExample]' started. 2015-06-18 14:48:43.676 XCTRunner[39404:602329] Continuing to run tests in the background with task ID 1 t = 1.99s Wait for app to idle t = 2.63s Find the "toggleButton" Switch t = 2.65s Tap the "toggleButton" Switch t = 2.65s Wait for app to idle t = 2.66s Find the "toggleButton" Switch t = 2.66s Dispatch the event t = 2.90s Wait for app to idle t = 3.10s Find the "toggleButton" Switch t = 3.10s Tap the "toggleButton" Switch t = 3.10s Wait for app to idle t = 3.11s Find the "toggleButton" Switch t = 3.11s Dispatch the event t = 3.34s Wait for app to idle t = 3.54s Find the "toggleButton" Switch t = 3.54s Tap the "MyButton" Button t = 3.54s Wait for app to idle t = 3.54s Find the "MyButton" Button t = 3.55s Dispatch the event t = 3.77s Wait for app to idle t = 4.25s Tap the "Okay" Button t = 4.25s Wait for app to idle t = 4.26s Find the "Okay" Button t = 4.28s Dispatch the event t = 4.51s Wait for app to idle t = 4.51s Find the "toggleButton" Switch Test Case '-[TempCam_UI_Tests.TempCam_UI_Tests testExample]' passed (4.526 seconds). Test Suite 'TempCam_UI_Tests' passed at 2015-06-18 14:48:47.129. Executed 1 test, with 0 failures (0 unexpected) in 4.526 (4.527) seconds Test Suite 'TempCam UI Tests.xctest' passed at 2015-06-18 14:48:47.129. Executed 1 test, with 0 failures (0 unexpected) in 4.526 (4.528) seconds Test Suite 'All tests' passed at 2015-06-18 14:48:47.130. Executed 1 test, with 0 failures (0 unexpected) in 4.526 (4.529) seconds ** TEST SUCCEEDED ** |
生成截图
无需额外的工作,可轻轻松得到截图。可为命令添加derivedDataPath选项,你可以告诉Xcode在什么地方储存测试结果,包括生成的截图。
1
2
3
4
5
6
|
xcodebuild -workspace App.xcworkspace \ -scheme "SchemeName" \ -sdk iphonesimulator \ -destination 'platform=iOS Simulator,name=iPhone 6,OS=9.0' -derivedDataPath './output' test |
Xcode会自动为每个测试操作生成截图,关于生成数据的更多信息,可查看Michele写的Test Logs in Xcode.
下一步
想要为多种语言和多种设备类型创建截图,你可能会需要像snapshot这样的工具,snapshot使用UI Automation, 不过现在已经弃用了。我目前用的是最新版的snapshot,可充分利用新UI Tests的功能,这样如果程序出错,那snapshot能展示更多细节结果和错误信息。
使用命令行工具运行Xcode 7 UI Tests的更多相关文章
- dedecms:织梦文章如何添加“自定义属性”标签(sql命令行工具)
dede织梦如何添加“自定义属性”标签“症状” 1.进入后台——系统——SQL命令行工具——运行SQL命令行,添加arcatt表字段: insert into`dede_arcatt`(sortid, ...
- Scrapy命令行工具简介
Windows 10家庭中文版,Python 3.6.4,virtualenv 16.0.0,Scrapy 1.5.0, 在最初使用Scrapy时,使用编辑器或IDE手动编写模块来创建爬虫(Spide ...
- Xcode 命令行工具 Command Line Tools
xcode命令行工具包是一个小型独立包,可供下载独立于Xcode的和允许您执行命令行开发OS X. 在OS X10.9,就以及没有clt的下载安装包了,需要使用命令在线安装. xcode-select ...
- 从命令行模式运行Windows管理工具。
从命令行模式运行Windows管理工具. 分类: Play Windows 2004-08-06 16:39 6076人阅读 评论(3) 收藏 举报 1.可以直接在开始-〉运行里面输入的管理工具: 文 ...
- 您可以从 Windows 命令行上运行 gcc、g++、ar、ranlib、dlltool 和其他一些 GNU 工具
Windows 上的安装为了在 Windows 上安装 GCC,您需要安装 MinGW.为了安装 MinGW,请访问 MinGW 的主页 www.mingw.org,进入 MinGW 下载页面,下载最 ...
- 命令行工具解析Crash文件,dSYM文件进行符号化
备份 文/爱掏蜂窝的熊(简书作者)原文链接:http://www.jianshu.com/p/0b6f5148dab8著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”. 序 在日常开发 ...
- [原创]使用命令行工具提升cocos2d-x开发效率(一)之TexturePacker篇
TexturePacker是一个常用的制作sprite sheet的工具,它提供了很多实用的功能. 一般我们制作sprite sheet都是使用他的gui版本,纯手工操作,就像下面这张图示的一样. 刚 ...
- [原创]使用命令行工具提升cocos2d-x开发效率(二)之CocosBuilder篇
如果你正在使用CocosBuilder或者是其他基于CocosBuilder源码改装而成的工具为你的游戏搭建场景或者UI,那你一定要看看这篇文章:) 你是否已经厌倦了无聊的手工publish操作? ...
- Expo大作战(六)--expo开发模式,expo中exp命令行工具,expo中如何查看日志log,expo中的调试方式
简要:本系列文章讲会对expo进行全面的介绍,本人从2017年6月份接触expo以来,对expo的研究断断续续,一路走来将近10个月,废话不多说,接下来你看到内容,将全部来与官网 我猜去全部机翻+个人 ...
随机推荐
- STM32命名原则
每种STM32的产品都由16个字母或数字构成的编号标示,用户向ST订货时必须使用这个编号指定需要的产品.这16个字符分为8个部分,下面通过一个例子说明它们的意义: STM32 F 103 C ...
- tar 解压常用压缩文件格式命令大全
常用压缩文件格式就那么几种,解压命令总结在此: 1 2 3 4 5 6 7 8 tar xzf filename.tar.gz tar xjf filename.tar.bz2 tar xzf f ...
- Linq常用语法详细
1.简单的linq语法 //1 var ss = from r in db.Am_recProScheme select r; //2 var ss1 = db.Am_recProScheme; // ...
- VWmare workstation12.5中出现的问题
安装VWmare Workstation12.5之后,出现只能从主机复制文件到虚拟机,但是虚拟机的文件不能直接拖到主机中进行复制.所以我们需要重新安装VWmare Tools. 在虚拟机的VM-> ...
- Isometric terrain
Isometric terrainhttp://forum.mapeditor.org/t/isometric-terrain/192/2 无透视地图的地形制作时,将每一贴图逆时针旋转45度,则比较容 ...
- python——有一种线程池叫做自己写的线程池
这周的作业是写一个线程池,python的线程一直被称为鸡肋,所以它也没有亲生的线程池,但是竟然被我发现了野生的线程池,简直不能更幸运~~~于是,我开始啃源码,实在是虐心,在啃源码的过程中,我简略的了解 ...
- Myeclipse的使用
一,错误解决 1, 现象:使用eclipse运行带有main函数的Java文件时,出现editor does not contain a main type的错误框 原因:原来这个class所在包没有 ...
- windows7 64,32位下scrapy爬虫框架的环境搭建
适用于python 2.7 64位安装 一.操作系统:WIN7 64位 二.python版本:2.7 64位(scrapy目前不支持3.x) 不确定位数的,看图 三.安装相关软件:(可以从我的百度网盘 ...
- spring设置全局异常处理器
1.spring设置全局异常,它的原理是向上捕获 spring.xml配置 <!--自定义全局异常处理器--> <bean id="globalExceptionResol ...
- 关于SQLite的伪随机数
--random() 的返回值范围是:[-2^63,(2^63)-1],而通常要的是最小为 0的随机数,于是就不能直接用了,解决办法: then col else -col end) result f ...