iOS unit testing instance variables -
i new ios development , trying write unit tests code. need access instance variables. way create category, write getter methods, , import test file?
here .m file
//imports @implementation viewcontroller{ nsarray* a; int b; //other variables } //methods here test file
#import "viewcontroller_tests.h" #import "viewcontroller.h" @implementation viewcontroller_tests{ viewcontroller *controller; } - (void)setup { [super setup]; controller = [[viewcontroller alloc] initwithnibname:nil bundle:nil]; } - (void)teardown { [super teardown]; } - (void)test1 { nsarray* a; //i want access variables here! } @end
i can see 2 solutions can use:
1: use uispec framework test function of view controller, e.g. "assert view controller has tableview x number of entries" (this regression test) , runs in simulator full gui.
2: use precompiler flags such #ifdef unit_tests either open access member variables or add accessor methods, using build settings define unit_tests in other preprocessor flags, compiled in unit tests.
Comments
Post a Comment