Chapter 5 of 10 at Apple Developer > Jump Right In is Define Your Data Model.
Download the answer at the end of this chapter whenever you like.
No you don't need to be them any time soon
Yea, they really do tell you to read and understand all of the voluminous "FoodTrackerTests.swift" file, even though they then tell you to delete most of what you just deciphered.
So you might rather delete what you're going to delete, then go back and understand just what remains.
<= Learning Objectives
<= Create a Data Model
<= Test Your Data
Always the pieces, sometimes the whole
Yea there's a glaring tupo of an entire example missing at <<< Your unit test class should look like this: >>>. In place of the example, they give you only its first line. Oh well. What they meant to say is, in order to demo your first test failure, your code should look like this:
import XCTest<= Test Your Data
@testable import FoodTracker
class FoodTrackerTests: XCTestCase {
//MARK: Meal Class Tests
func testMealInitializationSucceeds() {
let zeroRatingMeal = Meal.init(name: "Zero", photo: nil, rating: 0)
XCTAssertNotNil(zeroRatingMeal)
let positiveRatingMeal = Meal.init(name: "Positive", photo: nil, rating: 5)
XCTAssertNotNil(positiveRatingMeal)
}
func testMealInitializationFails() {
let negativeRatingMeal = Meal.init(name: "Negative", photo: nil, rating: -1)
XCTAssertNil(negativeRatingMeal)
let largeRatingMeal = Meal.init(name: "Large", photo: nil, rating: 6)
XCTAssertNil(largeRatingMeal)
let emptyStringMeal = Meal.init(name: "", photo: nil, rating: 0)
XCTAssertNil(emptyStringMeal)
}
}
Simulate an iPhone to fail your first test
Yes, testing your code as they suggest will trigger Xcode to open up a simulated iPhone, if you have quit Xcode and relaunched it since you last needed to run a simulated iPhone.
<= Test Your Data
Download and compare and commit
The download is 05_DefineYourDataModel. Your Commit Message can be "Define Your Data Model".
<= Wrapping Up
No comments:
Post a Comment