We are used to the test driven develop way.When i move to develop objective-c,i need write testcase too.
Finally I found some useful article (http://developer.apple.com/mac/articles/tools/unittestingwithxcode3.html).
1: Set up a Cocoa project follow the instructions.
2:New a target named TestCase
3: set testcase run path: Test Host and Bundle Loader
$(BUILT_PRODUCTS_DIR)/OCT.app/Contents/MacOS/OCT
4: select testcase and then build and run
Aslo there are some useful Assert wealthy to be remmenberd
OCUnit Macro | Purpose |
---|---|
STAssertNil(a1, description, ...) | Generates an error if a1 is not nil. |
STAssertNotNil(a1, description, ...) | Generates an error if a1 is nil. |
STAssertTrue(expression, description, ...) | Generates an error if expression does not evaluate to true |
STAssertFalse(expression, description, ...) | Generates an error if expression does not evaluate to false |
STAssertEqualObjects(a1, a2, description, ...) | Generates an error if a1 is not equal to a2. Both must be Objective-C objects. |
STAssertEquals(a1, a2, description, ...) | Generates an error if a1 is not equal to a2. Both must be C scalar values. |
STAssertEqualsWithAccuracy(left, right, accuracy, description, ...) | Generates an error if a1 and a2 are not within a certain amount of each other. Primarily for use with floats and doubles to take into account small rounding errors due to the way they store values. |
STAssertThrows(expression, description, ...) | Generates an error if expression does not throw an exception. |
STAssertThrowsSpecific(expression, specificException, description, ...) | Generates an error if expression does not throw an exception of a specified class. |
STAssertThrowsSpecificNamed(expr, specificException, aName, description, ...) | Generates an error if expression doesn’t throw an exception with a specific name. |
STAssertNoThrow(expression, description, ...) | Generates an error if expression throws an exception. |
STAssertNoThrowSpecific(expression, specificException, description, ...) | Generates an error if expression throws an exception of a specified class. |
STAssertNoThrowSpecificNamed(expr, specificException, aName, description, ...) | Generates an error if expression throws an exception with a specific name. |
STFail(description, ...) | Generates an error. |
STAssertTrueNoThrow(expression, description, ...) | Generates an error if expression is false or if it throws an exception. |
STAssertFalseNoThrow(expron, description, ...) | Generates an error if expression is true or if it throws an exception |