Tag Archives: Unit Testing

ReactiveCocoa – how to test asynchronous signal

I have signal like this:

It makes some job in background thread and then returns an array of ViewModels to display a list of time zones.

You can use RACSignal (Testing) category in RACSignal.h to test such signals.

My tests are following:

iOS Unit Test Examples / Snippets

In this article I will post common iOS Unit testing examples for testing of:

  1. Asynchronous loading of data using REST API
  2. Loading of a UIView
  3. Method call after UITableViewCell is clicked
  4. Static UITableView sections have correct number of rows
  5. Loading of a UIView from UIStoryboard
  6. IBOutlet connection
  7. Model logic
  8. UITableViewCell subclass
  9. IBAction / Method is implemented
  10. Testing bundle name

Asynchronous loading of data using REST API

Here [RSHTTPClient sharedClient] is an instance of AFHTTPSessionManager subclass. But it doesn’t matter, the main is the principle.

Loading of a UIView

Method call after UITableViewCell is clicked

Here we verify that method restoreHomeKitClicked is called when user selects a specific row in UITableView.

Static UITableView sections have correct number of rows

Loading of a UIView from UIStoryboard

IBOutlet connection

Model logic

Here we test that an array, that is formed inside our model has correct number of items. Model logic testing obviously can be different depending of logic itself.

UITableViewCell subclass

IBAction / Method is implemented

Testing bundle name

The last is a rare case, but helps to prevent someone changing a bundle name of project accidentally.