Unit Testing a Project with Spaces in Its Name

June 17th, 2019

Filed under: Xcode | Be the first to comment!

Suppose you have an Xcode project with spaces in the name. My App In your unit tests you want to import the module so you can access your app’s classes in your unit tests. If you import the app project with the spaces, @testable import My App You’ll get errors from the compiler. How do […]

Xcode 10: Running Tests in Random Order

November 6th, 2018

Filed under: Xcode | Be the first to comment!

In Xcode 10 you can tell Xcode to run your tests in random order. Open the scheme editor for your project and select the Test step. Click the Options button next to the test target to open a popover. Select the Randomize execution order checkbox to run your tests in random order.

Getting Started with Unit Testing in Swift 4

June 13th, 2018

Filed under: Cocoa, iOS Development, Mac Development, Xcode | Be the first to comment!

One of the most read articles on this blog is An Introduction to Swift Unit Testing. The article is almost four years old and uses Swift 1. Because of that I have decided to build upon that article here, updating the code to Swift 4 and adding an example project to unit test. The Project […]

Xcode 7: Profiling Unit Tests in Instruments

January 26th, 2016

Filed under: Instruments, Xcode | 1 comment

I learned about this tip from an Apple engineer on Apple’s developer forums and felt like sharing it here. Xcode 7 lets you profile unit tests in Instruments, using the following steps: Open the test navigator. Right-click on a test or a group of tests in the test navigator. Choose Profile “testMethod”, where testMethod is […]

@testable Import

July 6th, 2015

Filed under: Xcode | Be the first to comment!

A new feature added in Xcode 7 to simplify unit testing is the @testable import statement. Instead of making your application classes members of the unit testing target, which is what you had to do to unit test Swift code in Xcode 6, add the following statement to your unit testing classes: @testable import MyApp […]

An Introduction to Swift Unit Testing

July 17th, 2014

Filed under: Cocoa, Xcode | 4 comments

This article shows you how to get started unit testing Swift code in Xcode with XCTest. If you’ve written Objective-C unit tests using XCTest or OCUnit, you should be able to smoothly transition to Swift after reading the article. But Objective-C unit testing experience isn’t required to read this article. Because Xcode 6 is currently […]

Getting OCMock to Work with XCTest

October 7th, 2013

Filed under: Xcode | 1 comment

XCTest does not currently have built-in support for mock objects so you’ll need an external framework like OCMock for mock object support. OCMock versions 2.2 and later work with XCTest. I had only one problem getting OCMock to work with XCTest. When I ran my tests, I would get a warning saying that the test […]

Xcode 5: Unit Testing Changes

September 30th, 2013

Filed under: Xcode | 6 comments

One of the biggest areas of change in Xcode 5 involves unit testing. This post details those changes. Test Navigator Xcode 5 adds a test navigator to the available navigators on the left side of the project window. You can see an example of the test navigator in the following screenshot: The test navigator has […]

Introduction to Unit Testing with OCUnit

May 23rd, 2012

Filed under: Mac Development | 3 comments

In a previous post I covered how to setup OCUnit unit testing in Xcode 4. This post provides an introduction to writing unit tests with OCUnit, which is a unit testing framework for Objective-C code that comes with Xcode. Unit Testing Classes When writing unit tests with OCUnit, you will create one or more unit […]

Setting Up OCUnit Unit Testing in Xcode 4

May 15th, 2012

Filed under: Xcode | 1 comment

Xcode ships with OCUnit, which allows you to unit test Objective-C code. This post shows you how to setup Xcode 4 so you can unit test Cocoa and iOS applications. Create an Appropriate Project The easiest way to add unit testing support in Xcode 4 is to create a project that uses the Cocoa or […]