Database Reference
In-Depth Information
override
func
tearDown() {
super
.
tearDown
()
camperService
=
nil
coreDataStack
=
nil
}
tearDown
is the opposite of
setUp
, and is called after each test executes. Here, the
method will simply make all the properties
nil
, resetting the
CoreDataStack
after
every test.
There's only a single method on
CamperService
at this point, and that is
addCamper(_:phonenumber:)
. Still in
CamperServiceTests.swift
, create a new
method to test
addCamper
:
func
testAddCamper() {
let
camper =
camperService
.
addCamper
(
"Bacon Lover"
,
phoneNumber:
"910-543-9000"
)
XCTAssertNotNil
(camper,
"Camper should not be nil"
)
XCTAssertTrue
(camper?.
fullName
==
"Bacon Lover"
)
XCTAssertTrue
(camper?.
phoneNumber
==
"910-543-9000"
)
}
You create a camper with certain properties, then check to confirm that a camper
exists with the properties you expect.
Remove the
testExample
and
testPerformanceExample
methods from the class.
It's a simple test, but it ensures that if any logic inside of
addCamper
is modified, the
basic operation doesn't change. For example, if you add some new data validation
logic to prevent bacon-loving people from reserving campgrounds,
addCamper
might
return nil. This test would then fail, alerting you that either you made a mistake in
the validation or that the test needs to be updated.