olifante edited this page Aug 30, 2011 · 8 revisions


OJUnit is a simple unit test tool written in and for Objective-J. It’s based on the xUnit design. The OJUnit project can be found at cappuccino/ojunit.

Installation Instructions


Since Cappuccino is now using the narwhal platform you can use the tusk package manager to install OJUnit:
$ tusk install ojunit
After that you can use jake test to run all the tests.


You should be able to just run rake test and then use it. If that fails, you can also try git submodule init && git submodule update.


To use OJUnit with Cappuccino you need its sources.

If you are using 0.7b you should check it out into Tools/ojunit. One way to do it is to use git submodules (however Ross Boucher mentioned this being problematic when switching between branchessee Phillipe Lavalls sollution for a different way)

What I did was run rake submodules to set them up and then in the root of the repo git submodule add git://github.com/cappuccino/ojunit.git Tools/ojunit to check it out. Then afterwards you can update with git submodule update.

Using OJUnit with ojtest

OJUnit tests can be run using the ojtest command installed by rake. At the top-level directory of your project simply run

$ ojtest Object1Test.j Object2Test.j

with the filenames of all your tests. It is important that you are at your project’s top-level directory, or Objective-J may not be able to locate your files correctly.

Or, you can run all your tests using wildcards, like:

$ ojtest Tests/*/*Test.j

This will run all the tests with filenames that end in Test.j located in a subfolder of Tests/.

Writing OJUnit tests

Writing OJUnit tests is just like writing tests for other xUnit frameworks. Some conventions usually apply (although these are not required):

  • Test class names usually follow the pattern ClassNameTest (e.g. CPCollectionViewTest).

Your test classes must subclass OJTestCase. Each test case must start with test and usually has a signature like:

- (void)testObjectIsInitializedWithDefaultValues

You can optionally provide - (void)setUp and/or - (void)tearDown implementations. setUp will be run before any of the tests in the class are run and tearDown will be run after all tests in the class are run.

For methods that OJTestCase provides, see OJTestCase source.

For example tests, see Cappuccino’s tests.