Category Archives: testing

Unit Testing View Controllers and Asynchronous APIs

I have an application that I’m working on that uses Parse (a service that lets you persist objects in the cloud, perform queries, etc.).    Calls to the Parse APIs are initiated from the main thread and dispatched to the global queue, thus  completion of these calls happens asynchronously.

I wanted to write some unit tests to verify the functionality of my methods that interface with Parse.

Referencing the View Controller

My initial view controller is called EntryViewController.   This view controller instances a class called ParseConnection which serves as a model for all my Parse interactions.    All calls to methods in ParseConnection from EntryViewController are dispatched to the global queue.  Within ParseConnection, all the API calls are made synchronously in this background queue.

My first challenge was how to get a reference from my unit tests to EntryViewController.   I wanted to do this from the instance setUp method in my test suite class called ContactsOnlineBasicUnitTests, and store this reference in a property.   This setUp method is called before each test case is run.

@interface  ContactsOnlineBasicUnitTests ()

@property (strong, nonatomic) EntryViewController *entryViewController;


Continue reading

Setting up for Unit Testing

In my last post I talked about how to setup for Code Coverage and made a reference to unit testing. In this article I wanted to share my experience with setting up to run unit testing.

A great place to start is the Apple document Xcode Unit Testing Guide.

Setup target and initial test suite

Choose File > New > Target …
In the iOS section, select Other, then select the Cocoa Touch Unit Testing Bundle template.

Cocoa Touch Unit Testing Bundle template

Since my app is called ContactsOnline, I’ll name my product (new target) ContactsOnlineBasicUnitTests.

This creates a test suite by the same name ContactsOnlineBasicUnitTests.m, within a group called ContactsOnlineBasicUnitTests.

Unit-test targets define one or more test suites.

Continue reading