Database Reference
In-Depth Information
Note: The final project for this chapter included in the resources bundled with
this topic includes unit tests covering multiple scenarios for each method. You
can browse through the code there for even more examples.
Validation and refactoring
ReservationService will have some of the most complex logic to handle figuring out
if a camper is able to reserve a site. The unit tests for ReservationService will
require every service so far created to test its operation.
Create a new test class as you've done before:
1. Right-click Services under the CampgroundManagerTests group and click
New File .
2. Select Test Case Class . Click Next .
3. Name the class ReservationServiceTests (subclass of XCTestCase should
already be selected) and pick Swift for the language.
4. Make sure the CampgroundManagerTests target checkbox is the only target
selected. Click Create .
Replace the contents of the file with the following:
import Foundation
import CoreData
import XCTest
import CampgroundManager
class ReservationServiceTests: XCTestCase {
var campSiteService: CampSiteService !
var camperService: CamperService !
var reservationService: ReservationService !
var coreDataStack: CoreDataStack !
override func setUp() {
super . setUp ()
coreDataStack = TestCoreDataStack ()
camperService = CamperService (managedObjectContext:
coreDataStack . mainContext !, coreDataStack:
coreDataStack )
campSiteService = CampSiteService (managedObjectContext:
coreDataStack . mainContext !, coreDataStack:
coreDataStack )
 
Search WWH ::




Custom Search