Rightpoint / RZUtils

Rightpoint Commonly Used Tools
Other
122 stars 22 forks source link

iOS7 and running the unit tests #128

Open seanoshea opened 9 years ago

seanoshea commented 9 years ago

I'm not fully sure that this is definitely an issue, but am opening it as such after being prompted to do so on twitter (https://twitter.com/seanoshea/status/567809726965350400).

https://github.com/seanoshea/RZUtils/tree/unit-tests is a unit-testing branch that I've started to work on a little. The tests pass without any issues on iOS8, but layoutSubviews isn't being invoked on the containerView when the tests are run on iOS7.

Here's the output of the tests when run on iOS7:

Test Suite 'All tests' started at 2015-02-17 23:30:19 +0000
Test Suite 'RZUtilsTests.xctest' started at 2015-02-17 23:30:22 +0000
Test Suite 'RZAutoLayoutHelpersTest' started at 2015-02-17 23:30:22 +0000
Test Case '-[RZAutoLayoutHelpersTest testCenteringViews]' started.
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:109: error: -    [RZAutoLayoutHelpersTest testCenteringViews] : (([self roundedEquals:frameOne.origin.x valueTwo:375.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:110: error: -    [RZAutoLayoutHelpersTest testCenteringViews] : (([self roundedEquals:frameOne.origin.y valueTwo:375.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:111: error: -[RZAutoLayoutHelpersTest testCenteringViews] : (([self roundedEquals:frameOne.size.width valueTwo:250.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:112: error: -[RZAutoLayoutHelpersTest testCenteringViews] : (([self roundedEquals:frameOne.size.height valueTwo:250.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:114: error: -[RZAutoLayoutHelpersTest testCenteringViews] : (([self roundedEquals:CGRectGetMidX(frameOne) valueTwo:500.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:115: error: -[RZAutoLayoutHelpersTest testCenteringViews] : (([self roundedEquals:CGRectGetMidY(frameOne) valueTwo:500.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:119: error: -[RZAutoLayoutHelpersTest testCenteringViews] : (([self roundedEquals:frameTwo.origin.x valueTwo:412.5f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:120: error: -[RZAutoLayoutHelpersTest testCenteringViews] : (([self roundedEquals:frameTwo.origin.y valueTwo:335.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:121: error: -[RZAutoLayoutHelpersTest testCenteringViews] : (([self roundedEquals:frameTwo.size.width valueTwo:175.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:122: error: -[RZAutoLayoutHelpersTest testCenteringViews] : (([self roundedEquals:frameTwo.size.height valueTwo:330.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:124: error: -[RZAutoLayoutHelpersTest testCenteringViews] : (([self roundedEquals:CGRectGetMidX(frameTwo) valueTwo:500.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:125: error: -[RZAutoLayoutHelpersTest testCenteringViews] : (([self roundedEquals:CGRectGetMidY(frameTwo) valueTwo:500.0f]) is true) failed
Test Case '-[RZAutoLayoutHelpersTest testCenteringViews]' failed (0.005 seconds).
Test Case '-[RZAutoLayoutHelpersTest testCenteringWithOffsetViews]' started.
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:144: error: -[RZAutoLayoutHelpersTest testCenteringWithOffsetViews] : (([self roundedEquals:frameOne.origin.x valueTwo:397.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:145: error: -[RZAutoLayoutHelpersTest testCenteringWithOffsetViews] : (([self roundedEquals:frameOne.origin.y valueTwo:397.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:146: error: -[RZAutoLayoutHelpersTest testCenteringWithOffsetViews] : (([self roundedEquals:frameOne.size.width valueTwo:250.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:147: error: -[RZAutoLayoutHelpersTest testCenteringWithOffsetViews] : (([self roundedEquals:frameOne.size.height valueTwo:250.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:149: error: -[RZAutoLayoutHelpersTest testCenteringWithOffsetViews] : (([self roundedEquals:CGRectGetMidX(frameOne) valueTwo:522.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:150: error: -[RZAutoLayoutHelpersTest testCenteringWithOffsetViews] : (([self roundedEquals:CGRectGetMidY(frameOne) valueTwo:522.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:154: error: -[RZAutoLayoutHelpersTest testCenteringWithOffsetViews] : (([self roundedEquals:frameTwo.origin.x valueTwo:434.5f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:155: error: -[RZAutoLayoutHelpersTest testCenteringWithOffsetViews] : (([self roundedEquals:frameTwo.origin.y valueTwo:357.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:156: error: -[RZAutoLayoutHelpersTest testCenteringWithOffsetViews] : (([self roundedEquals:frameTwo.size.width valueTwo:175.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:157: error: -[RZAutoLayoutHelpersTest testCenteringWithOffsetViews] : (([self roundedEquals:frameTwo.size.height valueTwo:330.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:159: error: -[RZAutoLayoutHelpersTest testCenteringWithOffsetViews] : (([self roundedEquals:CGRectGetMidX(frameTwo) valueTwo:522.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:160: error: -[RZAutoLayoutHelpersTest testCenteringWithOffsetViews] : (([self roundedEquals:CGRectGetMidY(frameTwo) valueTwo:522.0f]) is true) failed
Test Case '-[RZAutoLayoutHelpersTest testCenteringWithOffsetViews]' failed (0.003 seconds).
Test Case '-[RZAutoLayoutHelpersTest testPinningViews]' started.
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:190: error: -[RZAutoLayoutHelpersTest testPinningViews] : (([self roundedEquals:frameOne.size.width valueTwo:RZAutoLayoutHelpersTestContainerWidth]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:191: error: -[RZAutoLayoutHelpersTest testPinningViews] : (([self roundedEquals:frameOne.size.height valueTwo:RZAutoLayoutHelpersTestContainerHeight]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:195: error: -[RZAutoLayoutHelpersTest testPinningViews] : (([self roundedEquals:frameTwo.origin.x valueTwo:17.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:196: error: -[RZAutoLayoutHelpersTest testPinningViews] : (([self roundedEquals:frameTwo.origin.y valueTwo:21.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:197: error: -[RZAutoLayoutHelpersTest testPinningViews] : (([self roundedEquals:frameTwo.size.width valueTwo:962.0f]) is true) failed
/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:198: error: -    [RZAutoLayoutHelpersTest testPinningViews] : (([self roundedEquals:frameTwo.size.height valueTwo:962.0f]) is true) failed
Test Case '-[RZAutoLayoutHelpersTest testPinningViews]' failed (0.001 seconds).
Test Suite 'RZAutoLayoutHelpersTest' failed at 2015-02-17 23:30:22 +0000.
 Executed 3 tests, with 30 failures (0 unexpected) in 0.008 (0.008) seconds
Test Suite 'RZAutoLayoutTests' started at 2015-02-17 23:30:22 +0000
Test Case '-[RZAutoLayoutTests testMultipleLevels]' started.
Test Case '-[RZAutoLayoutTests testMultipleLevels]' passed (0.000 seconds).
Test Case '-[RZAutoLayoutTests testParentChildAndUnrelated]' started.
Test Case '-[RZAutoLayoutTests testParentChildAndUnrelated]' passed (0.000 seconds).
Test Case '-[RZAutoLayoutTests testParentChildOrder1]' started.
Test Case '-[RZAutoLayoutTests testParentChildOrder1]' passed (0.000 seconds).
Test Case '-[RZAutoLayoutTests testReturnsSingleView]' started.
Test Case '-[RZAutoLayoutTests testReturnsSingleView]' passed (0.000 seconds).
Test Case '-[RZAutoLayoutTests testTwoUnrelatedViews]' started.
Test Case '-[RZAutoLayoutTests testTwoUnrelatedViews]' passed (0.000 seconds).
Test Suite 'RZAutoLayoutTests' passed at 2015-02-17 23:30:22 +0000.
 Executed 5 tests, with 0 failures (0 unexpected) in 0.000 (0.001) seconds
Test Suite 'RZBlockKVOTests' started at 2015-02-17 23:30:22 +0000
Test Case '-[RZBlockKVOTests testObservation]' started.
Test Case '-[RZBlockKVOTests testObservation]' passed (0.001 seconds).
Test Case '-[RZBlockKVOTests testObserverDeallocation]' started.
Test Case '-[RZBlockKVOTests testObserverDeallocation]' passed (0.000 seconds).
Test Case '-[RZBlockKVOTests testObserverRemoval]' started.
Test Case '-[RZBlockKVOTests testObserverRemoval]' passed (0.000 seconds).
Test Suite 'RZBlockKVOTests' passed at 2015-02-17 23:30:22 +0000.
 Executed 3 tests, with 0 failures (0 unexpected) in 0.001 (0.001) seconds
Test Suite 'RZUtilsTests.xctest' failed at 2015-02-17 23:30:22 +0000.
 Executed 11 tests, with 30 failures (0 unexpected) in 0.010 (0.012) seconds
Test Suite 'All tests' failed at 2015-02-17 23:30:22 +0000.
 Executed 11 tests, with 30 failures (0 unexpected) in 0.010 (2.711) seconds
Program ended with exit code: 1

I'm trying to force layoutSubviews with the following code:

- (void)forceConstraintsEvaluationForAllSubviewsOfView:(UIView *)view
{
    for (UIView *subview in view.subviews) {
        [self forceConstraintsEvaluationForAllSubviewsOfView:subview];
    }
    [view setNeedsLayout];
    [view layoutIfNeeded];
}

but it doesn't seem to be doing the trick on iOS7.

Is it required to be able to run the unit tests on iOS7 (the pod spec would seem to indicate so)? If so, might someone have a suggestion for how to force layoutSubviews to get called when the constrains are added to the testViewOne and testViewTwo.

ZevEisenberg commented 9 years ago

@Raizlabs/maintainers-ios do we require iOS 7 support in RZUtils? Or is that handled on a per-subspec basis?

seanoshea commented 9 years ago

If there's any opposition to merging in this branch due to the iOS7 issue, I can go back to the drawing board on this and see if I can tease out the reasons for why these tests might be failing on iOS7. If you guys have any suggestions or pointers as to why the tests might not be working, I'd be very interested in hearing more. FWIW, I did test that the constraints work fine in a dummy iOS 7 project. It just looks like I'm struggling to force layoutSubviews when running the unit tests.

KingOfBrian commented 9 years ago

We should definitely keep iOS 7 support. We also shouldn't have to do the forceConstraints method. If you run [self.contentView layoutIfNeeded], it works fine on iOS 8, but it's curiously failing on iOS 7.....

I tried spinning the runloop, and there was no change. I tried adding the view to a window, and the makeKeyWindow method blew up. I noticed that [UIApplication sharedApplication] returned nil, and realized that there's no test target we're attaching to, and no main.m with UIApplicationMain(argc, argv,.......])). I'm guessing that in iOS 7 something is setup that enables the constraint solver, and without attaching to a test target, the UI tests will be DOA. If you add a simple, simple test target with nothing but an app delegate (maybe just the main.m?), I bet these tests will start being a bit happier.

seanoshea commented 9 years ago

Thanks for the suggestion @KingOfBrian. Tried adding a test app target in 5f1f1c7b05fa3a7679f6acad401e69236bdcb28e - is this what you had in mind?

I can't seem to get the dependencies absolutely correct in the TestApp project as reporting a missing .h file:

/Users/Sean/dev/github/RZUtils/Tests/RZUtilsTests/RZAutoLayoutHelpersTest.m:31:9: 'UIView+RZAutoLayoutHelpers.h' file not found

I've tried adding the RZUtilsTests target as a dependent target of the App and the UnitTest target, but I can't seem to make the UIView+RZAutoLayoutHelpers.h file available to the test. Tried a link_with option in the Podfile, but no luck with that either.

KingOfBrian commented 9 years ago

Hey @seanoshea , I picked your branch up and found a few issues. AppDelegate.m didn't seem to be added, but I think the issues are with the cocoapods settings. Sometimes when modifying the podfile settings, it doesn't update this pane correctly: screen shot 2015-02-28 at 6 40 57 pm

One note on the layout -- I'd prefer to have RZUtilsTestApp and RZUtilsTestAppTests at the same level.

I wasn't able to get the tests to pass with out the AppDelegate.m, but I think if you clean up the CocoaPod's settings, you should be able to get things going.

Thanks!

seanoshea commented 9 years ago

Thanks again for the pointers @KingOfBrian. See 9ca40acf38c9e399a105bed1fe9dd7b26b8a1893 eb401839b708ef780a9e7516fd373d089014967a f54f79b72973e126ff1943facc4908b8ce181809 8235d107ede46b28fabd58dc8693a2a799a238ce for details on the test app. Is this what you had in mind?

Tried running the rake build and the tests that are left in the main test target pass fine. I guess the only thing remaining would be to ensure that the tests from the RZUtilsTestApp project are run whenever rake test is executed?

KingOfBrian commented 9 years ago

Yea the project layout looks good!

Few Notes:

seanoshea commented 9 years ago

Didn't know about XCTAssertEqualWithAccuracy - have switched over to that. Tested on iOS7 and iOS8 on iPhone4/iPhone5iPhone6/6+/iPad/iPad Retina and all tests appear to pass with the latest changes. See 890e24ec48e672d4e74475a31658bcf054322685, 689af6e99b6680376a24b3cc8c4274c42e5a1000 and f4c2cc93dec92041946ee3046f53166612a86e0f for details.

seanoshea commented 9 years ago

@KingOfBrian @ZevEisenberg it appears that there are two ways of quietening the layout constraints complaining about conflicts. One way is to remove the size constraints before adding any new pin* constraints:

- (void)testPinningViews {
    [self.testViewOne removeConstraints:@[[self.testViewOne rz_pinnedWidthConstraint],     [self.testViewOne rz_pinnedHeightConstraint]]];
    [self.testViewTwo removeConstraints:@[[self.testViewTwo rz_pinnedWidthConstraint],     [self.testViewTwo rz_pinnedHeightConstraint]]];

On the other hand, you could just override the intrinsicContentSize of testViewOne and testViewTwo to look like:

@interface RZTestViewOne : UIView

@end

@implementation RZTestViewOne

- (CGSize)intrinsicContentSize {
    return CGSizeMake(250.0f, 250.0f);
}

@end

@interface RZTestViewTwo : UIView

@end

@implementation RZTestViewTwo

- (CGSize)intrinsicContentSize {
    return CGSizeMake(175.0f, 330.0f);
}

@end

I'd tend to go for option 1, but I don't have a firm opinion. Would you have any advice or preference here?

Also, in terms of running ALL the tests on the command line, I'd imagine the best way would be to alter the RZUtilsTestApp schema to look like http://imgur.com/oFsvR5o?

seanoshea commented 9 years ago

See https://github.com/Raizlabs/RZUtils/pull/139 for a possible solution to this.