Created
July 24, 2021 06:46
-
-
Save ykpoh/3475d76f31c93edf3693d1c46eec705b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import XCTest | |
@testable import SpaceXLaunch | |
class LaunchTests: XCTestCase { | |
var sut: Launch! | |
override func setUpWithError() throws { | |
// Put setup code here. This method is called before the invocation of each test method in the class. | |
try super.setUpWithError() | |
try givenSUTFromJSON() | |
} | |
override func tearDownWithError() throws { | |
// Put teardown code here. This method is called after the invocation of each test method in the class. | |
sut = nil | |
try super.tearDownWithError() | |
} | |
// MARK: - Type Tests | |
func testConformsToDecodable() { | |
XCTAssertTrue((sut as Any) is Decodable) // cast silences a warning | |
} | |
func testConformsToEquatable() { | |
XCTAssertEqual(sut, sut) // requires Equatable conformance | |
} | |
func testDecodableSetsId() { | |
XCTAssertEqual(sut.id, "5eb87cd9ffd86e000604b32a") | |
} | |
func testDecodableSetsName() { | |
XCTAssertEqual(sut.name, "FalconSat") | |
} | |
func testDecodableSetsDetails() { | |
XCTAssertEqual(sut.details, "Engine failure at 33 seconds and loss of vehicle") | |
} | |
func testDecodableSetsDateUTC() { | |
XCTAssertEqual(sut.date_utc, DateFormatter.iso8601Full.date(from: "2006-03-24T22:30:00.000Z")) | |
} | |
func testDecodableSetsUpcoming() { | |
XCTAssertEqual(sut.upcoming, false) | |
} | |
func testDecodableSetsSuccess() { | |
XCTAssertEqual(sut.success, false) | |
} | |
func testDecodableSetsRocket() { | |
XCTAssertEqual(sut.rocket, "5e9d0d95eda69955f709d1eb") | |
} | |
private func givenSUTFromJSON() throws { | |
let decoder = JSONDecoder() | |
let data = try Data.fromJSON(fileName: "\(LaunchResponse.self)") | |
let launchResponse = try decoder.decode(LaunchResponse.self, from: data) | |
sut = launchResponse.docs?.first | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment