Show Menu
Cheatography

GHUnit Cheat Sheet (DRAFT) by

ghunit cheatsheet

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Example

// For iOS
#import <GH­Uni­tIO­S/G­HUn­it.h­>
// For Mac OS X
//#import <GH­Uni­t/G­HUn­it.h­>

@interface Exampl­eTest : GHTestCase { }
@end

@imple­men­tation Exampl­eTest

- (BOOL)­sho­uld­Run­OnM­ain­Thread {
// 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)­set­UpClass {
// Run at start of all tests in the class
}

- (void)­tea­rDo­wnClass {
// Run at end of all tests in the class
}

- (void)­setUp {
// Run before each test method
}

- (void)­tea­rDown {
// Run after each test method
}

- (void)­testFoo {
NSString *a = @"fo­o";
GHTest­Log­(@"I can log to the GHUnit test console: %@", a);

// Assert a is not NULL, with no custom error descri­ption
GHAsse­rtN­otN­ULL(a, nil);

// Assert equal objects, add custom error descri­ption
NSString *b = @"ba­r";
GHAsse­rtE­qua­lOb­jec­ts(a, b, @"A custom error message. a should be equal to: %@.", b);
}

- (void)­testBar {
// Another test
}

@end
 

Assert Macros

GHAsse­rtNoErr (a1, descri­ption, ...)
GHAsse­rtErr (a1, a2, descri­ption, ...)
GHAsse­rtN­otNULL ** (a1, descri­ption, ...)
GHAsse­rtNULL (a1, descri­ption, ...)
GHAsse­rtN­otE­quals (a1, a2, descri­ption, ...)
GHAsse­rtN­otE­qua­lOb­jects (a1, a2, desc, ...)
GHAsse­rtO­per­ation (a1, a2, op, descri­ption, ...)
GHAsse­rtG­rea­terThan (a1, a2, descri­ption, ...)
GHAsse­rtG­rea­ter­Tha­nOr­Equal (a1, a2, descri­ption, ...)
GHAsse­rtL­essThan (a1, a2, descri­ption, ...)
GHAsse­rtL­ess­Tha­nOr­Equal (a1, a2, descri­ption, ...)
GHAsse­rtE­qua­lSt­rings (a1, a2, descri­ption, ...)
GHAsse­rtN­otE­qua­lSt­rings (a1, a2, descri­ption, ...)
GHAsse­rtE­qua­lCS­trings (a1, a2, descri­ption, ...)
GHAsse­rtN­otE­qua­lCS­trings (a1, a2, descri­ption, ...)
GHAsse­rtE­qua­lOb­jects (a1, a2, descri­ption, ...)
GHAsse­rtE­quals (a1, a2, descri­ption, ...)

Running from the Command Line

Copy RunTes­ts.sh and RunIPh­one­Sec­uri­tyd.sh into your project in the same directory as the xcodeproj file.
|
|For the script enter: sh RunTes­ts.sh
 

Assert Macros (cont.)

GHAbso­lut­eDi­ffe­rence (left,­right) (MAX(l­eft­,ri­ght­)-M­IN(­lef­t,r­ight))
GHAsse­rtE­qua­lsW­ith­Acc­uracy (a1, a2, accuracy, descri­ption, ...)
GHFail (descr­iption, ...)
GHAsse­rtNil (a1, descri­ption, ...)
GHAsse­rtN­otNil (a1, descri­ption, ...)
GHAsse­rtTrue (expr, descri­ption, ...)
GHAsse­rtT­rue­NoThrow (expr, descri­ption, ...)
GHAsse­rtFalse (expr, descri­ption, ...)
GHAsse­rtF­als­eNo­Throw (expr, descri­ption, ...)
GHAsse­rtT­hrows (expr, descri­ption, ...)
GHAsse­rtT­hro­wsS­pecific (expr, specif­icE­xce­ption, descri­ption, ...)
GHAsse­rtT­hro­wsS­pec­ifi­cNamed (expr, specif­icE­xce­ption, aName, descri­ption, ...)
GHAsse­rtN­oThrow (expr, descri­ption, ...)
GHAsse­rtN­oTh­row­Spe­cific (expr, specif­icE­xce­ption, descri­ption, ...)
GHAsse­rtN­oTh­row­Spe­cif­icNamed (expr, specif­icE­xce­ption, aName, descri­ption, ...)

Enviro­nment Variables

TEST
To run a specific test (from the command line). Use TEST="G­HSl­owT­est­/te­stS­low­A" for a specific test or TEST="G­HSl­owT­est­" for a test case
GHUNIT­_RE­RAISE
Default NO; If an exception is encoun­tered it re-raises it allowing you to crash into the debugger
GHUNIT­_AU­TORUN
Default NO; If YES, tests will start automa­tically
GHUNIT­_AU­TOEXIT
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_­JUN­IT_XML
Default NO; Whether to write out JUnit XML output. For Jenkins CI integr­ation
JUNIT_­XML_DIR
Default to temporary directory. Specify to have files written to a different directory. For Jenkins CI integr­ation.