Database Reference
In-Depth Information
return true
}
var campSite = campSiteService . addCampSite ( 1 ,
electricity: true , water: true )
self . waitForExpectationsWithTimeout ( 2.0 ) {
error in
XCTAssertNil (error, "Save did not occur" )
}
}
Run the unit tests, and everything should pass. At this point, you should be feeling
a bit of paranoia. Maybe these tests are broken and they always pass? It's time to
do some test-driven development and get the buzz that comes from turning red
tests to green!
Note: Test-Driven Development (TDD) is a way of developing an application
by writing a test first, then incrementally implementing the feature until the
test passes. The code is then refactored for the next feature or improvement.
TDD methodology goes way beyond the scope of this chapter but may be
something you'll find useful. The steps you're covering here will help you use
TDD if you do decide to follow it.
Add the following methods to CampSiteServiceTests.swift to test getCampSite() :
func testGetCampSiteWithMatchingSiteNumber() {
campSiteService.addCampSite( 1 , electricity: true ,
water: true )
let campSite = campSiteService.getCampSite( 1 )
XCTAssertNotNil(campSite, "A campsite should be returned" )
}
func testGetCampSiteNoMatchingSiteNumber() {
campSiteService . addCampSite ( 1 , electricity: true ,
water: true )
let campSite = campSiteService . getCampSite ( 2 )
XCTAssertNil (campSite, "No campsite should be returned" )
}
Search WWH ::




Custom Search