Unit and Functional testing iPhone code? - iphone

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.

Related

Functional testing automation tools for iPad/iPhone?

There doesn't seem to be many choices out there for running functional tests on the iPad/iPhone. A quick search brought up a few options: FoneMonkey, Frank, UI Automation.
Does anyone have experience with any of these or have suggestions for better solutions?
I'm the FoneMonkey project founder, so admittedly a bit biased, but I would strongly recommend you give FoneMonkey a try. It provides robust recording and playback for native iPhone and iPad apps, and you can easily extend custom scripts with Objective-C logic to automate virtually any UI scenario.
The next release (due out later this week) generates UIAutomation-based tests in JavaScript, as well as ready-to-run OCunit tests.
Stu Stern
I also found these:
UISpec: http://code.google.com/p/uispec/
Squish: http://www.froglogic.com/products/editions.php
Are there some more?
This is another tool that could be used for UI testing.
Debugging with console environment.
libcat : interactive iPhone application development
https://github.com/wookay/libcat
There is also one more app in app store. Name of app is TestStudio from Telerik. (http://www.telerik.com/)
It is good but you require Mac Book to install their extension where you can register your app and then use that app on iPad to test.
Hope this will help.

xUnit Testing Framework for Mac/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)

There is any tool for UI Unit Testing iPhone application(Not SenTestCase)

I am looking for any tool or approach using which I can do UI unit test for iPhone application, I am aware of SenTestCase framework however which is used to do that testing for code I am looking for UI unit testing.
Check out UISpec http://code.google.com/p/uispec/
It's an open source ui testing framework being developed for the iphone.
Cheers!
You can use OCUnit/SenTest to do unit tests in the UI as well as on the other code - this blog post from Chris Hanson is about Cocoa UI unit testing but the same principles apply to Cocoa Touch.
Try libcat for UI testing and automation.
also providing console mode.
interactive iPhone application development
https://github.com/wookay/libcat
If you're willing to build a special testing target for your app, you can use the Ruby-based Cucumber framework to drive an iPhone GUI remotely: http://www.slideshare.net/undees/iphone-meets-cucumber
--Ian
There is also Fone Monkey which allows you to record actions and then add assertions.
http://www.gorillalogic.com/fonemonkey
Google has a pretty cool set of tools as well.
http://code.google.com/p/google-toolbox-for-mac/wiki/iPhoneUnitTesting

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.

Do OCUnit and OCMock work on the iPhone SDK?

I simply could not make it work, and I am wondering if I am wasting my time, or if I am simply stupid!
Sorry I don't have the exact error I have right now. But I just want to know if it work or not!
I don't know whether OCUnit works with iPhone, but there is an iPhoneUnitTesting framework available from Google Code.
Colin Barrett has a blog post about OCMock and the iPhone.
Not so sure about OCMock, but OCUnit support is now included in iPhone 2.2 SDK.
You can download an example application from Stanford iPhone Application Programming CS193P Lecture 19.
Sen:te (the creator of the framework) explains how to use OCUnit with an iPhone project: http://www.sente.ch/s/?p=535&lang=en.
I created some OCUnit tests for an iPhone app, but in order to run the tests I had to compile for Mac OS X, not iPhone OS, and switching back and forth was a pain.
The Google framework is cleaner, they can run the tests in the simulator or on the device.
I got hung up on the same thing. I finally found the answer on Mitch's World then reposted the solution on my site. The quick fix is to add the OCMock.framework folder to /Library/frameworks and reference it from there. For whatever reason XCode doesn't want to add folders external to its natural framework seach to the path. Until I find out more this is the best we can do.
-Cliff
At the time of writing OCUnit "just works" on the iPhone. Apple are shipping templates that works out of the box.
Take a look here. You'll find a Xcode template you can use that has OCUnit and OCMock all ready setup for you.
You might be interested in this project which integrats OCMock & gh-unit (based on Google toolkit)
Unit test