OCUnit Framework
OCUnit Framework
-
OCUnit: A unit testing framework built into Xcode.
-
GHUnit: A third party unit testing framework with some extra features.
-
OCMock: This helps you in writing the mock objects to handle mocking in test cases.
-
XCTest: A unit testing framework that is introduced with Xcode 5.
@end
-
It must start with the word test. OCUnit treats methods with the test prefix as test methods and runs them automatically.
-
It does not take any argument.
-
It always returns void.
-
It supports generic assert framework, that is explained below.
-
STAssertEqualObjects: Asserts two Cocoa objects are equal.
-
STAssertEqual: Asserts that two variables of a primitive data type, such as integers, are equal.
-
STAssertEqualsWithAccuracy: Asserts that two floating-point variables are equal. This assertion allows you to deal with small inaccuracies in floating-point arithmetic.
-
STAssertFalse: Asserts that given condition evaluates to false.
-
STAssertFalseNoThrow: Asserts that given condition is false and no exceptions are thrown.
-
STAssertNil: Asserts that a pointer is nil.
-
STAssertNoThrow: Asserts that no exceptions are thrown.
-
STAssertNoThrowSpecific: Asserts that no exceptions of a specific class are thrown.
-
STAssertNoThrowSpecificNamed: Asserts that a specific exception is not thrown.
-
STAssertNotNil: Asserts that a pointer is not nil.
-
STAssertThrows: Asserts that an exception is thrown.
-
STAssertThrowsSpecific: Asserts that an exception of a specific class is thrown.
-
STAssertThrowsSpecificNamed: Asserts that a specific exception is thrown.
-
STAssertTrue: Asserts that a condition evaluates to true.
-
STAssertTrueNoThrow: Asserts that a condition evaluates to true and no exceptions are thrown.
setUp and tearDown Methods
-
setUp: If you have some initialization code block that you need to perform before running each test case, you can place that code in the setUp() method and remove the duplicate code in your tests.
-
tearDown: This method complements setUp method. If you want to run a code block that executes after every test case, that cleanup code should go to tearDown. A common case of using the tearDown method is to free any memory you allocated in the setUp() method.