How to run and debug unit tests for an iPhone application

血红的双手。 提交于 2019-11-28 17:18:37

This post is intended as a "How-to" more than a real question. Therefore this answer is just meant to allow me to mark the "How-to" as "answered". This will probably be flagged by the community as irregular. I'm up for suggestions on where to post future "How-to" articles.

One final note though on this topic. For those who still wonder whether writing unit tests is worth it I would definitely say Yes!

I am currently writing an application with CoreData and retrieval of data from a web service (xml parsing). The complete model can be tested and debugged without having to:

  1. run the actual application on the simulator or device. Not having to use the device to run the tests is a huge gain of time. It's the difference between 2 minutes and 5 seconds per run.
  2. without the need to create views or controllers when testing the model. The complete development and testing can focus on the model only in the first iteration. Once the model is cleared for integration the rest of the development can follow.

To debug the xml parsing I can simply use "hard-coded" files which I completely control.

The crux is of course to write the tests as you implement features in the code. It really is a time saver down the line in terms of debugging of the complete application.

Voilà, I'll leave it at that.

I was able to run the test case in debugger in the following simple steps:

  1. Product > Build For > Testing
  2. Put a break point in part of the test you want to debug
  3. Product > Test

This is on Xcode 6.0.1 and seems much more convenient than the long procedure described above.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!