I'm planning to write couple applications for iPhone and wonder if there are any Unit Testing and Code Coverage Frameworks for Objective-C?
For unit testing iPhone apps there is OCTest or Googles iPhoneUnitTesting
For a mocking framework you can use OCMock. Here is the guide to getting it to work with the iPhone.
GCov can be used for code coverage.
Related
I'm using GHUnit in my project and i need learn about OCMock for complete my Unit Tests (but i am new to this). I'm working with xcode 3.2.5
somebody knows about a good tutorial on OCMock?
Thanks.
I just did a quick google search for "OCMock" and it found a couple of small tutorials on OCMock. But not in combination with GHUnit. I use this combination and it works very well. OCMock has no problem working within the GHUnit framework. I have both of them in my projects as static frameworks. I'd also suggest have a read through the documentation on the OCMock website. Although I think it's a little light.
Ok, it's not a tutorial but take a look at the sources for dUsefulStuff and dXml. the code is pre me using static frameworks, but it does use both OCMock and GHUnit together. More so in dUsefulStuff which I started after dXml. dXml has around 130 unit tests and dUsefulStuff around 30 or 40 so there should eb enough to give you an idea. I should be updating both of these libaries soon.
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)
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
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.
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.