Introducing Swift Testing
If you are the lead developer of a large project involving many developers, it would not be practical for you to review everyone’s source code in detail, and in some cases, you would not be able to view the source code at all. Instead, you would issue specifications on what a class is supposed to do, and it would be the developer’s job to write the class for you.
As an example, let’s look at the initializer code for the JournalEntry
class in the JRNL app:
init?(rating: Int, title: String, body: String, photo: UIImage? = nil, latitude: Double? = nil, longitude: Double? = nil) {
if title.isEmpty || body.isEmpty || rating < 0 || rating > 5 {
return nil
}
self.date = Date()
self.rating = rating
self.title = title
self.body = body
self.photoData = photo?.jpegData(compressionQuality: 1.0)
self.latitude = latitude
self.longitude = longitude
}
As you can see, you can only create valid JournalEntry
...