Example
// For iOS
#import <GHUnitIOS/GHUnit.h>
// For Mac OS X
//#import <GHUnit/GHUnit.h>
@interface ExampleTest : GHTestCase { }
@end
@implementation ExampleTest
- (BOOL)shouldRunOnMainThread {
// By default NO, but if you have a UI test or test dependent on running on the main thread return YES.
// Also an async test that calls back on the main thread, you'll probably want to return YES.
return NO;
}
- (void)setUpClass {
// Run at start of all tests in the class
}
- (void)tearDownClass {
// Run at end of all tests in the class
}
- (void)setUp {
// Run before each test method
}
- (void)tearDown {
// Run after each test method
}
- (void)testFoo {
NSString *a = @"foo";
GHTestLog(@"I can log to the GHUnit test console: %@", a);
// Assert a is not NULL, with no custom error description
GHAssertNotNULL(a, nil);
// Assert equal objects, add custom error description
NSString *b = @"bar";
GHAssertEqualObjects(a, b, @"A custom error message. a should be equal to: %@.", b);
}
- (void)testBar {
// Another test
}
@end |
|
|
Assert Macros
GHAssertNoErr (a1, description, ...)
GHAssertErr (a1, a2, description, ...)
GHAssertNotNULL ** (a1, description, ...)
GHAssertNULL (a1, description, ...)
GHAssertNotEquals (a1, a2, description, ...)
GHAssertNotEqualObjects (a1, a2, desc, ...)
GHAssertOperation (a1, a2, op, description, ...)
GHAssertGreaterThan (a1, a2, description, ...)
GHAssertGreaterThanOrEqual (a1, a2, description, ...)
GHAssertLessThan (a1, a2, description, ...)
GHAssertLessThanOrEqual (a1, a2, description, ...)
GHAssertEqualStrings (a1, a2, description, ...)
GHAssertNotEqualStrings (a1, a2, description, ...)
GHAssertEqualCStrings (a1, a2, description, ...)
GHAssertNotEqualCStrings (a1, a2, description, ...)
GHAssertEqualObjects (a1, a2, description, ...)
GHAssertEquals (a1, a2, description, ...) |
Running from the Command Line
Copy RunTests.sh and RunIPhoneSecurityd.sh into your project in the same directory as the xcodeproj file.
|
|For the script enter: sh RunTests.sh |
|
|
Assert Macros (cont.)
GHAbsoluteDifference (left,right) (MAX(left,right)-MIN(left,right))
GHAssertEqualsWithAccuracy (a1, a2, accuracy, description, ...)
GHFail (description, ...)
GHAssertNil (a1, description, ...)
GHAssertNotNil (a1, description, ...)
GHAssertTrue (expr, description, ...)
GHAssertTrueNoThrow (expr, description, ...)
GHAssertFalse (expr, description, ...)
GHAssertFalseNoThrow (expr, description, ...)
GHAssertThrows (expr, description, ...)
GHAssertThrowsSpecific (expr, specificException, description, ...)
GHAssertThrowsSpecificNamed (expr, specificException, aName, description, ...)
GHAssertNoThrow (expr, description, ...)
GHAssertNoThrowSpecific (expr, specificException, description, ...)
GHAssertNoThrowSpecificNamed (expr, specificException, aName, description, ...) |
Environment Variables
TEST |
To run a specific test (from the command line). Use TEST="GHSlowTest/testSlowA" for a specific test or TEST="GHSlowTest" for a test case |
GHUNIT_RERAISE |
Default NO; If an exception is encountered it re-raises it allowing you to crash into the debugger |
GHUNIT_AUTORUN |
Default NO; If YES, tests will start automatically |
GHUNIT_AUTOEXIT |
Default NO; If YES, will exit upon test completion (no matter what). For command line MacOSX testing |
GHUNIT_CLI |
Default NO; Specifies that the tests are being run from the command line. For command line MacOSX testing |
WRITE_JUNIT_XML |
Default NO; Whether to write out JUnit XML output. For Jenkins CI integration |
JUNIT_XML_DIR |
Default to temporary directory. Specify to have files written to a different directory. For Jenkins CI integration. |
|