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.

Tasks

  • + clearTestImages

    Clear all test images in the documents directory

  • + saveToDocumentsWithImage:filename:

    Save an image to the documents directory as filename

  • – isCLIDisabled

    Whether the test class should be run as a part of command line tests. By default this is YES since there are some small differences in rendering from the command line vs rendering in the simulator

  • – 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.

  • – 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.

Class Methods

clearTestImages

Clear all test images in the documents directory

+ (void)clearTestImages

Declared In

GHViewTestCase.h

saveToDocumentsWithImage:filename:

Save an image to the documents directory as filename

+ (void)saveToDocumentsWithImage:(UIImage *)image filename:(NSString *)filename

Parameters

image

Image to save

filename

Filename for the saved image

Declared In

GHViewTestCase.h

Instance Methods

isCLIDisabled

Whether the test class should be run as a part of command line tests. By default this is YES since there are some small differences in rendering from the command line vs rendering in the simulator

- (BOOL)isCLIDisabled

Return Value

YES if this test class is disabled for command line tests

Declared In

GHViewTestCase.h

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