GHViewTestCase Class Reference
Inherits from | GHTestCase : NSObject |
Declared in | GHViewTestCase.h GHViewTestCase.m |
Overview
View verification test case.
Supports GHVerifyView, which renders a view and compares it against a saved image from a previous test run.
@interface MyViewTest : GHViewTestCase { }
@end
@implementation MyViewTest
- (void)testMyView {
MyView *myView = [[MyView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
GHVerifyView(myView);
}
@end
In order to record results across test runs, the PrepareUITests.sh script needs to be run as a build step. This script copies any test images (saved locally in $PROJECT_DIR/TestImages) to the app bundle so that calls to GHVerifyView have images from previous runs with which to compare.
After changes to views are approved in the simulator, the CopyTestImages.sh script should be run manually in Terminal. This script copies any approved view changes back to the project directory. Images are saved with filenames of the following format:
[test class name]-[test selector name][UIScreen scale]-[# of call to GHVerifyView in selector]-[view class name].png
Note that because of differences in text rendering between retina and non-retina devices/simulators, different images are saved for test runs using retina then non-retina.
Also note that there are commonly rendering differences across iOS versions. Therefore it is common for tests to fail when they are run using a different iOS version then the one that created the saved test image. This also applies to tests that are run at the command line (the xcodebuild flag ‘-sdk iphonesimulator’ usually corresponds to the latest iOS simulator available).
Class Methods
clearTestImages
Clear all test images in the documents directory.
+ (void)clearTestImages
Declared In
GHViewTestCase.h
Instance Methods
sizeForView:
Size for a given view. Subclasses can override this to provide custom sizes for views before rendering. The default implementation returns contentSize for scrollviews and returns self.frame.size for all other views.
- (CGSize)sizeForView:(UIView *)view
Parameters
- view
View for which to calculate the size
Return Value
Size at which the view should be rendered
Declared In
GHViewTestCase.h
verifyView:filename:lineNumber:
Called from the GHVerifyView macro. This method should not be called manually. Verifies that a view hasn’t changed since the last time it was approved. Raises a GHViewChangeException if the view has changed. Raises a GHViewUnavailableException if there is no image from a previous run.
- (void)verifyView:(UIView *)view filename:(NSString *)filename lineNumber:(int)lineNumber
Parameters
- view
View to verify
- filename
Filename of the call to GHVerifyView
- lineNumber
Line number of the call to GHVerifyView
Declared In
GHViewTestCase.h