xcode 是否有关于可可触摸自动化 UI 测试的好教程?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5393190/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there a good tutorial on cocoa touch automated UI testing?
提问by memmons
Typically I find that nearly all my most important test cases for iPhone development revolve around UI testing rather than business logic or data testing. I'm not very familiar with automated UI testing in the XCode environment. Can someone point me to a good tutorial or book?
通常,我发现几乎所有最重要的 iPhone 开发测试用例都围绕 UI 测试而不是业务逻辑或数据测试。我对 XCode 环境中的自动化 UI 测试不是很熟悉。有人可以指点我一个好的教程或书籍吗?
UPDATE
This question was written several years ago and UI testing has come a long way since then. Using the UI Automation is still an option, but the KIF Frameworkis a much better solution for functional testing now, IMO.
更新
这个问题是几年前写的,从那时起 UI 测试已经走了很长一段路。使用 UI 自动化仍然是一种选择,但KIF 框架现在是一个更好的功能测试解决方案,IMO。
From KIF's github page:
来自 KIF 的 github 页面:
KIF, which stands for Keep It Functional, is an iOS integration test framework. It allows for easy automation of iOS apps by leveraging the accessibility attributes that the OS makes available for those with visual disabilities.
KIF builds and performs the tests using a standard XCTest testing target. Testing is conducted synchronously in the main thread (running the run loop to force the passage of time) allowing for more complex logic and composition. This also allows KIF to take advantage of the Xcode 5 Test Navigator, command line build tools, and Bot test reports.
KIF 代表 Keep It Functional,是一个 iOS 集成测试框架。它通过利用操作系统为视障人士提供的辅助功能属性,可以轻松实现 iOS 应用程序的自动化。
KIF 使用标准 XCTest 测试目标构建和执行测试。测试在主线程中同步进行(运行运行循环以强制时间流逝)允许更复杂的逻辑和组合。这也让 KIF 能够利用 Xcode 5 Test Navigator、命令行构建工具和 Bot 测试报告。
回答by Brad Larson
Your best bet will be to use the UI Automation instrument that debuted with iOS 4.0. This can be scripted to test out many aspects of your user interface.
您最好的选择是使用随 iOS 4.0 推出的 UI 自动化工具。这可以编写脚本来测试用户界面的许多方面。
Apple provides a great introduction to this tool in the video for the WWDC 2010session 306 - "Automating User Interface Testing with Instruments". I demonstrate how to set up scripts and do testing in the video for the "Testing" session of my advanced iOS development course on iTunes U. My notes on UI Automation from that class, including sample scripts, can be found here.
Apple 在WWDC 2010session 306 - “Automating User Interface Testing with Instruments”的视频中对该工具做了很好的介绍。我在 iTunes U 上的高级 iOS 开发课程的“测试”会话的视频中演示了如何设置脚本和进行测试。我在该课程中关于 UI 自动化的笔记,包括示例脚本,可以在这里找到。
Additionally, you might want to look at James Turner's article "How to use UIAutomation to create iPhone UI tests" and Alex Vollmer's "Working with UIAutomation".
此外,您可能想查看 James Turner 的文章“如何使用 UIAutomation 创建 iPhone UI 测试”和 Alex Vollmer 的“使用 UIAutomation”。
回答by Jonah
What are you really trying to test? I agree that testing view interaction is important but find that I can usually construct a unit or integration test which tests the view or the view and it's controller to validate this behavior without attempting to drive the entire app via the UI.
你真正想测试什么?我同意测试视图交互很重要,但我发现我通常可以构建一个单元或集成测试来测试视图或视图及其控制器来验证此行为,而无需尝试通过 UI 驱动整个应用程序。
For example http://blog.carbonfive.com/2010/03/10/testing-view-controllers/has examples of tests which test that UIKit views are bound to IBActions or have appropriate delegate's and that a controller responds to those action or delegate messages appropriately. There's no need to actually drive a UIButton
or UITableView
since I'm willing to trust that those classes actually work and instead only need to test my use and configuration of them.
例如http://blog.carbonfive.com/2010/03/10/testing-view-controllers/有测试 UIKit 视图是否绑定到 IBActions 或具有适当的委托以及控制器响应这些操作或适当地委派消息。没有必要实际驱动 a UIButton
orUITableView
因为我愿意相信这些类确实有效,而只需要测试我对它们的使用和配置。
For custom view components you can send UIResponder
messages directly in your tests and assert that they behave as expected, again without driving the entire UI.
对于自定义视图组件,您可以UIResponder
直接在测试中发送消息并断言它们的行为符合预期,同样无需驱动整个 UI。
Can you provide an example of the sort of behavior you want to test?
你能提供一个你想要测试的行为的例子吗?