Last active
October 1, 2018 16:02
-
-
Save ccabanero/ac7237e4591092130326 to your computer and use it in GitHub Desktop.
Sample iOS Unit Tests: Working with a ViewController composed of Custom Views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func testControllerCanPresentSchoolDataWithCustomSchoolView() { | |
| // get target CustomView | |
| let subviews = self.viewControllerUnderTest.scrollView.subviews | |
| var schoolViews = [SchoolView]() | |
| for currentView in subviews { | |
| if(currentView.isKindOfClass(SchoolView)) { | |
| schoolViews.append(currentView as! SchoolView) | |
| } | |
| } | |
| // number of schools | |
| let expectedNumberOfSchoolViews = 1 | |
| let actualNumberOfSchoolViews = schoolViews.count | |
| XCTAssertEqual(expectedNumberOfSchoolViews, actualNumberOfSchoolViews) | |
| let schoolModel = self.model.schools | |
| let schoolView = schoolViews.first | |
| // confirm proper presentation of name in custom SchoolView | |
| let expectedModelName = schoolModel.name | |
| let actualViewName = schoolView?.schoolName | |
| XCTAssertEqual(expectedModelName, actualViewName) | |
| // confirm proper presentation of level in custom SchoolView | |
| let expectedModelLevel = schoolModel.level | |
| let actualViewLevel = schoolView?.schoolLevel | |
| XCTAssertEqual(expectedModelLevel, actualViewLevel) | |
| // confirm proper presentation of district in custom SchoolView | |
| let expectedModelDistrict = schoolModel.district | |
| let actualViewDistrict = schoolView?.district | |
| XCTAssertEqual(expectedModelDistrict, actualViewDistrict) | |
| // confirm proper presentation of location in custom SchoolView | |
| let expectedModelLocation = schoolModel.location | |
| let actualViewLocation = schoolView?.location | |
| XCTAssertEqual(expectedModelLocation, actualViewLocation) | |
| // confirm proper presentation of rating in custom SchoolView | |
| let expectedModelRating = String(schoolModel.rating) | |
| let actualViewRating = schoolView?.ratingTitle | |
| XCTAssertEqual(expectedModelRating, actualViewRating) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment