xUnit Testing Framework for Mac/iPhone - iphone

Does anyone know of any xUnit testing frameworks for the Mac OS, more specifically for the iPhone OS? I've seen a couple online, google-toolbox-for-mac & objcUnit, but they don't seem to have had any development on them for a long time.
Are there any Objective-C developers out there that perform unit testing and if you do what tools do you use?

gh-unit is a great framework and is actively maintained. it has a GUI.
ocunit is bundled with Xcode.
XcodeUnitTestGUI which is fairly immature, but works and provides a GUI for ocunit based tests (disclaimer -- this is my project).

OCUnit (shipped with Xcode) is a full xUnit-style testing framework that is integrated with Xcode (failures show up as linked build errors) and works on the iPhone and OS X. The Google Toolbox for Mac provides additional functionality (including UI testing and gcov support) on top of OCUnit. I'm not sure where you got the idea that it's not under active development. The last change was only 4 days ago (at the time of this post). For a mock framework, check out OCMock, an OCUnit-integrated mocking library (you may find that Objective-C's dynamic nature makes unit testing in general and mocking in particular much easier than expected by those accustomed to C/C++/C#/Java).
Believe it or not, Objective-C developers do do unit testing.

UnitTest++ is a very light weight, but powerful unit testing framework that I like a lot. It's site is: http://unittest-cpp.sourceforge.net/.
I've written a blog article about integrating it into an iPhone development environment, for more information you can see here: http://acornheroes.com/?p=152
Hope this helps.

I agree that OCUnit is a great xUnit tool. Integration with Xcode is solid, and it works well with OCMock. It's also hard to overstate the value of Apple being committed to the code — there is certainly room for improvement, but it's solid and still maintained. Xcode also integrates pretty nicely with gcov, a GNU tool for instrumenting code coverage. A few links...
http://cocoaheads.byu.edu/resources/unit-testing-cocoa
http://cocoaheads.byu.edu/resources/unit-testing-and-code-coverage-xcode
http://chanson.livejournal.com/182472.html
To back up Barry, yes, lots of Objective-C developers do unit testing, including inside Apple. (Just ask #bbum about CoreData unit tests...) For examples of what you can do, feel free to raid my side project:
http://dysart.cs.byu.edu/CHDataStructures/ (API documentation)
http://dysart.cs.byu.edu/CHDataStructures/coverage/source/ (coverage report)
http://dysart.cs.byu.edu/chsvn/CHDataStructures/ (browse Subversion)

Related

what are the main limitations of titanium as a mobile development platform?

I intend to start an iphone/android project with the titanium SDK for mobile. Do you know what are the main feature-wise pitfalls to avoid ? what sort of features will be very hard or impossible to achieve ?
I understand that there is a plugin system to circumvent these limitations. Do you have information on that ?
Thank you for your help,
Jerome Wagner
I have yet to find a particular piece of Android functionality that is missing from Titanium. Not sure if widgets are in the current 1.5.1 mobile release or are coming in 1.6. In any case, the coverage is pretty decent, as you will see if you try out the "kitchen sink" app.
But here are some things I find lacking:
Titanium's Android support is still much buggier than iPhone support. For instance, I can't get global events to work properly--that's pretty important functionality.
documentation isn't complete; the API docs are skimpy
you're on your own; Appcelerator employees don't bother to answer questions online (even when they concern obvious bugs on their end), unless you subscribe to a support plan
That said, I've found developing Android apps with Titanium to be much more enjoyable than dealing with the Android SDK!
I agree with most of what #Drew stated above.
The API documentation is for the "most part" pretty complete, yes there are a few missing pieces, but hey the framework is free, they push releases pretty frequently and all the source code is available for you to go through yourself. You also have full access to the Continuous Integration Builds
I believe the 1.6.0 release has addressed additional issues with Andorid support, there is also a bug tracking system for you to investigate and report issues.
You are not on your own any more than with any other similar framework... Occasionally employees will review specific issues that show up in the Q&A Forum but the forum is very active and there is tons of community support. I would be surprised if you could write most of an application from just cutting and pasting from the Q&A questions and you will find the rest in the Kitchen Sink Example or Tweetanium Example Projects.
You asked about a plugin system. Titanium offers the ability to develop your own custom native modules.
The Titanium's Module Developers Guide (PDF) isn't the best, but it will get you started.
As Drew said, many of the Titanium's Android support is buggier compared to iPhone.
Titanium is meant for people who never wanted to learn the native iphone and Android programming. If you know to develop applications using objective C and you wanted to develop applications for iPhone then don’t even think of Titanium, the same case applies to Android too. Only if you are lazy to learn a language, you can opt for Titanium.
1.The size of the Application is a big concern here.
2. Some of the features in Android which was shown to be working in developer reference were not working. Even after being filed as bugs, they were not updated in developer’s reference that it works only in iPhone. For example, “focus” events of the window is handled only in iPhone and never in Android.
To get to know in details, the problems Titanium can bring you read the following post:
http://mobworld.wordpress.com/2011/01/10/titanium-framework/

Architecting a Complex iPhone Application?

I am comming from an enterprise java development organization where we did development in nicely seperated re-usable layers. Persistency layers, Service layers, etc etc.
Now, I am looking for iPhone example apps or documentation on how to architecture complex iPhone projects. Most books & apple examples show you very limited code & architecture. They are not usable imo.
What I am also looking for is info on how to setup a continuous-integration build system which runs all my unit tests on code checkin & reports the unit test findings to a system where we can see the results.
For our java projects, we use svn, mvn & sonar for this. What's apple's equivalent for this setup? Is it even possible?
So, to summarize my questions:
Q1: Are there any examples or books on complex iPhone project architecture?
Q2: How do we setup a continuous-integration build system?
How complex of an example would you like? This question links to a number of non-Apple open source iPhone applications, including my own. Some of the applications out there are relatively complex.
As far as design goes, I'd highly recommend the book Cocoa Design Patterns. While not strictly for the iPhone (given Cocoa's beginnings at NeXT and more recent presence on the Mac), the design patterns covered are core to the architecture of the Cocoa frameworks and Cocoa applications.
I'd also recommend paying for the WWDC 2009 videos and watching the sessions "iPhone User Interface Design", "Effective iPhone App Architecture", and "Prototyping iPhone User Interfaces". There are a lot of good suggestions for architecting iPhone applications in these sessions.
I've used unit tests with my applications, but I have not done any form of continuous-integration building. However, this question looks to have a lot of good information on doing continuous integration with Xcode.
The heritage of the iPhone dates back to OpenStep by NeXT Computer. For some time, NeXT's primary focus was custom, enterprise applications. The technologies that are in-play on the iPhone are well proven in enterprise environments. NeXT was one of the orginal advocates of object technology, patterns, and MVC in particular.
That said, some of what used to be available in Openstep is now gone. NeXT had a radically advanced ORM system (Enterprise Objects Framework - http://en.wikipedia.org/wiki/Enterprise_Objects_Framework) that, although is still in use internally at Apple and powers iTunes/etc, is now deprecated for customers using Objective-C (a Java version still exists). A lite ORM, Core Data (http://developer.apple.com/macosx/coredata.html), has taken its place and is now available on the iPhone. SQLite (which is awesome) is also bundled on the iPhone and available for developers.
Another fly in the ointment is that the current version of XCode for the iPhone has a limited grasp of subprojects/frameworks, so it is more difficult to partition reusable code than it used to be. Tim Wood, of Omni, provides some details on how to manage frameworks within XCode on the iPhone (http://blog.omnigroup.com/2008/10/01/using-frameworks-in-iphone-applications/) Unfortunately, the process is not as easy as it ought to be.
I am not sure what books are available, but almost any former Openstep developer is going to have enterprise development expertise. You might consider pulling one into your project to help things along.
svn and mvn are available/bundled on OS X. There are also options for pulling in other, open source packages through systems like fink or MacPorts:
http://www.finkproject.org/about.php
http://www.macports.org/
http://github.com/mxcl/homebrew
There are also several framework options that support TDD.
Test Driven Design for iPhone Native apps
It does not look like sonar groks Objective-C at this time. Depending on your options, maybe you could develop a module for this?

Availability of older sample code for iPhone 2.2

We've been programming an iPhone application under iPhone OS 3.1, but the client has now decided he wants us to redo the existing codebase to run under 2.2. One of the nice pieces of built-in functionality we used under 3.1 was the UISearchDisplayController functionality for searching UITableViews, but that functionality was not available previously and I'm not sure how to create the equivalent code under 2.2 from scratch.
Long story short, does anyone know where I can obtain earlier sample code? The TableSearch example apparently existed under 2.2 and would likely be very useful to me, but I don't know how to obtain it. When I go to look online at the available Apple sample code, I'm redirected to the latest 3.1 versions, which don't do me any good.
Howard
I didn't have any luck tracking down that sample code either. You could try the wayback machine though.
Btw, just to give you some stats to take to your client. Currently > 75% of iPhone OS users are on 3.0 or better according to 3rd party sources. Writing code for <25% (and decreasing) of a market is generally not a good idea. It sticks you with code that is harder to maintain and test, etc., etc. I'm sure you know all this. Anyway, you should really see if you can convince them to drop 2.2.1 support.

How does unit testing on the iPhone work?

Do I need special libraries for this, or can I just create a huge class that trys to instantiate every object of my project and test all the methods in there? How's that done in theory?
Googling "unit testing iPhone" gives this excellent link as the first hit:
To sum up, Google Toolbox provides a good infrastructure for unit testing on iPhone.
If you're targeting iPhone OS 2.2 or later, you can use the version of OCUnit that's bundled with Xcode. There's a good blog article by Kailoa Kadano about this on Mobile Orchard. OCUnit is a unit testing framework that's similar to the well known JUnit framework from the Java world.
You can always do "poor man's unit testing" by creating a simple test program that uses the assert() macro in the C header assert.h or the NSAssert() macros in Cocoa/Cocoa-touch. That's not a horrible way to get started doing unit testing, but I'd really recommend looking at OCUnit or another unit testing framework eventually.
Which ever way you structure your unit tests, you'll want to create a separate target in your Xcode project to build and run the tests.
GHUnit is awesome.
I really love Kiwi: BDD (RSpec) for iPhone & iPad.
For a comprehensive answer, check out
iOS Tests/Specs TDD/BDD and Integration & Acceptance Testing.

Unit and Functional testing iPhone code?

I just sat in on a seminar about developing apps for the iPhone. The speaker told me that there is NOTHING available for writing unit tests or functional tests for your iPhone software.
Is this true? Is there really no testing story for the iPhone as of now?
Yes you can do unit testing, I hope the seminar didn't cost too much.
Do OCUnit and OCMock work on the iPhone SDK?
Not true. Before SDK 2.2 there wasn't an official Apple sanctionned unit testing support, but they've since added OCUnit support, which is documented on the Apple website.
Do OCUnit and OCMock work on the iPhone SDK?
Google provides a great toolkit (Google Toolbox for Mac)
http://code.google.com/p/google-toolbox-for-mac/wiki/iPhoneUnitTesting
I think Google's is a bit more complete because you can also do some functionnal user interface tests.
Hope that helps.
Others have pointed out the available options, but I'll point out that even if there weren't any unit-testing frameworks available, there is nothing preventing you from rolling your own. Unit test frameworks aren't that complicated, so lack of one is no excuse.
No, this is not true. As of iPhone SDK 2.2, OCUnit works fine. In addition there are other open-source unit test libraries you can use with the iPhone.
http://developer.apple.com/tools/unittest.html
Sen:te (the creator of the testing framework included with Xcode) explains how to use OCUnit with an iPhone project: http://www.sente.ch/s/?p=535&lang=en.
Gorilla Logic has just open sourced FoneMonkey, a true record/playback functional testing tool for the iPhone that works with OCUnit.
You can learn more at http://www.gorillalogic.com/fonemonkey.