Setting Up iOS Logic Tests [Part 2]

Wed Feb 13 2013 | Mark Struzinski

This is part 2 in a multi-part series on iOS unit testing and integration testing. In the last post, we discussed setting up the project and adding some dependencies with CocoaPods.

Today, I’m going to go through setting up some initial code to use the 3rd party libraries to make sure that the libraries are working. Then we’ll set up logic tests and see what breaks with CocoaPods (spoiler: compiler errors ahead!).

SVProgressHUD

First, let’s hook up SVProgressHUD

  1. Open ViewController.m and import SVProgressHUD: #import "SVProgressHUD.h”
  2. In viewDidLoad, create an SVProgressHUD indicator, then dismiss it after 2 seconds:
-(void)viewDidLoad{
  [super viewDidLoad];
  [SVProgressHUD showWithStatus:@"Running..."];
  double delayInSeconds = 2.0;
  dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW,
		(int64_t)	(delayInSeconds * NSEC_PER_SEC));
  dispatch_after(popTime, dispatch_get_main_queue(), ^(void) {
    [SVProgressHUD dismiss];
  });
}

You should be able to run this code now and see a progress indicator with a spinner and the text “Running….”. It should disappear after 2 seconds.

Great! This proves one of our CocoaPods libraries is communicating with the app’s main project and is working properly.

Next we’ll move onto Core Data with Magical Record.


This is a post in the Unit Testing Beginner Series series.

Other posts in this series:

This is part 4 in a multi-part series on iOS unit testing and integration testing. In the last post, we discussed setting up Core Data and the Magical Record library. This week, we’re going to set up our logic testing bundle. Let’s get started.

This is part 3 in a multi-part series on iOS unit testing and integration testing. In the last post, we discussed setting up SVProgressHUD.

This is part 2 in a multi-part series on iOS unit testing and integration testing. In the last post, we discussed setting up the project and adding some dependencies with CocoaPods.

Today, I’m going to go through setting up some initial code to use the 3rd party libraries to make sure that the libraries are working. Then we’ll set up logic tests and see what breaks with CocoaPods (spoiler: compiler errors ahead!).

I’m continuing on my task to get a full project using iOS unit tests and integration tests. My first step is to set up logic tests in Xcode. I recently watched an excellent unit testing course on Lynda. In that course, Ron Lisle goes over the advantages of using logic tests. The most compelling factor in using logic tests over application tests is speed.

I have wanted to get better at unit testing and the tooling around it for some time. I usually start out determined to get a good amount of the code covered by unit tests, and to possibly get some UI tests built around user interactions. Unfortunately, deadlines intervene, and the tests get abandoned. With my most recent project, I decided to put all of these practices in place.