iphone - UI 单元测试?
当谈到为 UI 编写单元测试时,您编写测试的目的是什么?
- 您测试每种方法吗? (例如:方法返回正确的数据)
- 或者您测试功能吗? (确保表填充了它应该填充的数据)
我是否需要模拟除我正在测试的项目之外的所有内容?假设我正在测试以确保表视图正确填充?我嘲笑其他一切吗?
请提供尽可能详细的信息
When it comes to writing unit testing for UI what do you write test for?
- Do you test each method? (EX: a method returns the correct data)
- Or do you test the functionalities? (Making sure that the table populates the data it suppose to)
Do I need to mock everything except the item I am testing? Let's say I am testing to make sure a table view populates correctly? Do i mock everything else?
Please provide as much details as possibe
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我将尝试以一般性的方式回答这个问题。
在测试类似 UI 的代码时,将测试目标定为距离 UI 本身“一步之遥”通常是一个好主意。前任。如果可能的话,针对模型而不是 UI 本身运行。这样它就不那么脆弱了。我不熟悉 iOS UI 测试自动化,但此类事情往往会因最小的布局更改等而中断。
I'll try to answer this in a general way.
When testing UI-ish code it's often a good idea to target the tests "one step away" from the UI itself. Ex. run against the models instead of the UI itself if possible. It's much less brittle this way. I'm not familiar with iOS UI test automation but these sort of things tend to break upon the smallest layout changes etc.
我建议您看一下 Gorilla Logic 的 FoneMonkey。他们有一个非常好的实用程序来编写单元测试,它实际上是从用户的角度进行测试的。检查 UI 是否应有的样子,即。正确加载,包含正确的值等。
您甚至可以在匿名环境中运行它,例如。持续集成服务器等
I'll suggest you take a look at FoneMonkey by Gorilla Logic. They have a very nice utility for writing unit test which actually tests from the users perspective, aka. check that the UI is as it should be, ie. loads correctly, contains the correct values, etc.
You can even run it in a faceless environment, eg. Continuous Integration server, etc.