Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the best way to unit test Objective-C code?

What frameworks exist to unit test Objective-C code? I would like a framework that integrates nicely with Apple Xcode.

like image 838
Kim Avatar asked Aug 28 '08 19:08

Kim


People also ask

What can be used for unit testing in C?

The most scalable way to write unit tests in C is using a unit testing framework, such as: CppUTest. Unity. Google Test.

Does C have unit testing?

A Unit Testing Framework for CCUnit is a lightweight system for writing, administering, and running unit tests in C. It provides C programmers a basic testing functionality with a flexible variety of user interfaces.


2 Answers

Xcode includes XCTest, which is similar to OCUnit, an Objective-C unit testing framework, and has full support for running XCTest-based unit tests as part of your project's build process. Xcode's unit testing support is described in the Xcode Overview: Using Unit Tests.

Back in the Xcode 2 days, I wrote a series of weblog posts about how to perform some common tasks with Xcode unit testing:

  • Unit testing Cocoa frameworks
  • Debugging Cocoa framework unit tests
  • Unit testing Cocoa applications
  • Debugging Cocoa application unit tests

Despite using OCUnit rather than XCTest, the concepts are largely the same.

Finally, I also wrote a few posts on how to write tests for Cocoa user interfaces; the way Cocoa is structured makes it relatively straightforward, because you don't have to spin an event loop or anything like that in most cases.

  • Trust, but verify.
  • Unit testing Cocoa user interfaces: Target-Action
  • Unit testing Cocoa user interfaces: Cocoa Bindings

This makes it possible to do test-driven development for not just your model-level code but also your controller-level and even view-level code.

like image 88
Chris Hanson Avatar answered Oct 12 '22 12:10

Chris Hanson


Check out GHUnit by Gabriel Handford:

"The goals of GHUnit are:

Runs unit tests within XCode, allowing you to fully utilize the XCode Debugger. A simple GUI to help you visualize your tests. Show stack traces. Be installable as a framework (for Cocoa apps) with a simple (or not) target setup; or easy to package into your iPhone project."

like image 42
elasticrat Avatar answered Oct 12 '22 12:10

elasticrat