Open seanoshea opened 9 years ago
@Raizlabs/maintainers-ios do we require iOS 7 support in RZUtils? Or is that handled on a per-subspec basis?
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.
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.
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.
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:
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!
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?
Yea the project layout looks good!
Few Notes:
layoutIfNeeded
. Otherwise we're not testing what's actually running. It appears that in iOS 7.x, the container view is shrinking down. You might be able to avoid this by setting the intrinsicContentSize on RZAutoLayoutHelpersContainerView
. XCTAssertEqualWithAccuracy
for float comparison, it will read a bit better. Also, why is the allowable delta 1.0f
? Larger than I thought, it's not just a float storage issue. If you could add a comment to the float to clarify the intent, that would help.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.
@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?
See https://github.com/Raizlabs/RZUtils/pull/139 for a possible solution to this.
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 thecontainerView
when the tests are run on iOS7.Here's the output of the tests when run on iOS7:
I'm trying to force
layoutSubviews
with the following code: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 thetestViewOne
andtestViewTwo
.