Permalink
Browse files

Re-enabling GHViewTestCase for command line tests. Filling out some m…

…ore documentation. Including screen density with image filename
  • Loading branch information...
1 parent 6701bcd commit 02d42ec6bdf7b171974000dcca8115ad6cc55a20 @johnboiles johnboiles committed Nov 2, 2011
View
@@ -149,4 +149,13 @@
*/
- (void)log:(NSString *)message;
+/*!
+ Whether the test class should be run as a part of command line tests.
+ By default this is NO. Subclasses can override this method to disable
+ test classes that are problematic at the command line.
+
+ @result YES if this test class is disabled for command line tests
+ */
+- (BOOL)isCLIDisabled;
+
@end
View
@@ -55,6 +55,10 @@ - (void)handleException:(NSException *)exception {
NSLog(@"%@", [GHTesting descriptionForException:exception]);
}
+- (BOOL)isCLIDisabled {
+ return NO;
+}
+
#pragma mark Logging
- (void)log:(NSString *)message {
View
@@ -71,7 +71,19 @@ reason:@"GHVerifyView can only be called from within a GHViewTestCase class"] ra
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.
+ 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).
*/
@interface GHViewTestCase : GHTestCase {
NSInteger imageVerifyCount_;
@@ -90,15 +102,6 @@ reason:@"GHVerifyView can only be called from within a GHViewTestCase class"] ra
*/
+ (void)saveToDocumentsWithImage:(UIImage *)image filename:(NSString *)filename;
-/*!
- 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
-
- @result YES if this test class is disabled for command line tests
- */
-- (BOOL)isCLIDisabled;
-
/*!
Size for a given view. Subclasses can override this to provide custom sizes
for views before rendering. The default implementation returns contentSize
View
@@ -199,13 +199,6 @@ - (void)_setUp {
imageVerifyCount_ = 0;
}
-- (BOOL)isCLIDisabled {
- // There seem to be some weird text rendering inconsistencies when views are rendered
- // when run from the command line, vs when views are rendered in the simulator. For now
- // We're only supporting tests in the simulator.
- return YES;
-}
-
- (CGSize)sizeForView:(UIView *)view {
// If the view is a UIScrollView, return the contentSize
if ([view isKindOfClass:[UIScrollView class]]) {
@@ -221,8 +214,13 @@ - (void)verifyView:(UIView *)view filename:(NSString *)filename lineNumber:(int)
// Fail if the view has CGSizeZero
if (CGSizeEqualToSize(view.frame.size, CGSizeZero)) [[NSException ghu_failureInFile:filename atLine:lineNumber withDescription:@"View must have a nonzero size in GHVerifyView"] raise];
- // View testing file names have the format [test class name]-[test selector name]-[# of verify in selector]-[view class name]
- NSString *imageFilename = [NSString stringWithFormat:@"%@-%@-%d-%@.png", NSStringFromClass([self class]), NSStringFromSelector(currentSelector_), imageVerifyCount_, NSStringFromClass([view class])];
+ // View testing file names have the format [test class name]-[test selector name]-[UIScreen scale]-[# of verify in selector]-[view class name]
+ NSString *imageFilename = [NSString stringWithFormat:@"%@-%@-%1.0f-%d-%@.png",
+ NSStringFromClass([self class]),
+ NSStringFromSelector(currentSelector_),
+ [[UIScreen mainScreen] scale],
+ imageVerifyCount_,
+ NSStringFromClass([view class])];
UIImage *originalViewImage = [[self class] readImageWithFilename:imageFilename];
CGSize viewSize = [self sizeForView:view];
@@ -149,4 +149,13 @@
*/
- (void)log:(NSString *)message;
+/*!
+ Whether the test class should be run as a part of command line tests.
+ By default this is NO. Subclasses can override this method to disable
+ test classes that are problematic at the command line.
+
+ @result YES if this test class is disabled for command line tests
+ */
+- (BOOL)isCLIDisabled;
+
@end
@@ -71,7 +71,19 @@ reason:@"GHVerifyView can only be called from within a GHViewTestCase class"] ra
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.
+ 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).
*/
@interface GHViewTestCase : GHTestCase {
NSInteger imageVerifyCount_;
@@ -90,15 +102,6 @@ reason:@"GHVerifyView can only be called from within a GHViewTestCase class"] ra
*/
+ (void)saveToDocumentsWithImage:(UIImage *)image filename:(NSString *)filename;
-/*!
- 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
-
- @result YES if this test class is disabled for command line tests
- */
-- (BOOL)isCLIDisabled;
-
/*!
Size for a given view. Subclasses can override this to provide custom sizes
for views before rendering. The default implementation returns contentSize
@@ -11,6 +11,7 @@
@implementation YKUIImageViewControl
+@dynamic image;
@synthesize imageView=_imageView;
- (id)initWithFrame:(CGRect)frame {

0 comments on commit 02d42ec

Please sign in to comment.