One Thing You Should Avoid While Unit Testing iOS Apps

So you are into some mobile testing services? You will surely be doing some work with Unit Tests, right? It is, indeed a great method to test all kinds of apps, however it does have downsides and pitfalls. Let’s take iOS app testing as our little example. Despite numerous amazing things you may achieve with properly designed unit tests there are deep dark roads you really don’t want to go down with. Here is a nice example: do avoid application delegate!

Why avoid application delegate in iOS unit testing?

Want a great suggestion of what you can do while unit testing app delegate? You should simply run away. Or, better, avoid it from the very beginning. Simply don’t include this into your unit tests and test target. Why? Well, unit test runtime differs from an environment to an environment meaning time required for tests in a simulation and on an actual device are not the same. This means app delegate testing will probably simply fail and result with not much more than a mere time loss.

What to do instead?

A great idea would be to stuff your code you are willing to test inside cozy NSObject ancestor classes, thus saving yourself from loads of headaches. Separate classes grant access to strings or arrays or other objects that are easily created and you will be safe from things like UIApplication or NSBuilder, which is nice.

An example straight from practice: imagine yourself fetching some data from your server. You can put in a separate class like the ServerFetcher, which inherits from your NSObject. This rids you from a necessity of injecting some code of yours straight inside view controller. This way things are done much easier.

This approach works insanely well for me, however I certainly realize that there is never the perfect path in software and especially in testing. So tell me, what do you think and share your own ideas in the comments!


TestFort Blog

About TestFort Blog

TestFort blog is an official blog of TestFort QA Lab company and is dedicated to various QA and software testing issues.


no comments yet

Be the first to comment this post!

Would you like to share your thoughts?

Software testing & QA blog by TestFort © 2017

×