Skip to content

Instantly share code, notes, and snippets.

View ykpoh's full-sized avatar

Yk Poh ykpoh

  • Melaka, Malaysia
View GitHub Profile
import XCTest
class LaunchResponseTests: XCTestCase {
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
}
override func tearDownWithError() throws {
// Put teardown code here. This method is called after the invocation of each test method in the class.
import XCTest
@testable import SpaceXLaunch // 1
class LaunchResponseTests: XCTestCase, DecodableTestCase { // 2
var sut: LaunchResponse! // 3
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() // 4
import Foundation
import XCTest
protocol DecodableTestCase: class {
associatedtype T: Decodable
var sut: T! { get set }
}
extension DecodableTestCase {
func givenSUTFromJSON(fileName: String = "\(T.self)") throws {
let decoder = JSONDecoder()
import Foundation
import XCTest
extension Data {
public static func fromJSON(fileName: String) throws -> Data {
let bundle = Bundle(for: TestBundleClass.self)
let url = try XCTUnwrap(bundle.url(forResource: fileName, withExtension: "json"))
return try Data(contentsOf: url)
}
}
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()
import Foundation
@testable import SpaceXLaunch
import Alamofire // 1
class MockDataRequest: DataRequestProtocol { // 2
// 3
static var statusCode: Int = 200
static var data: Data?
var dataResponse = AFDataResponse<Any>(
@testable import SpaceXLaunch
import Alamofire
enum MockAPIServiceError: Error {
case permissionDenied
}
class MockAPIService: APIServiceProtocol { // 1
enum Status {
case success
import XCTest
@testable import SpaceXLaunch
import Alamofire
class APIServiceTests: XCTestCase {
// 1
var mockSessionManager: MockSessionManager!
var mockDataRequest: MockDataRequest!
var mockBaseUrlString: String!
var sut: APIService!
import XCTest
@testable import SpaceXLaunch
class LaunchListTableViewCellViewModelTests: XCTestCase {
// 1
var sut: LaunchListTableViewCellViewModel!
var cell: LaunchListTableViewCell!
override func setUpWithError() throws {
// Put setup code here. This method is called before the invocation of each test method in the class.
import XCTest
@testable import SpaceXLaunch
import Alamofire
import RxSwift
class LaunchListViewModelTests: XCTestCase {
var sut: LaunchListViewModel!
var mockAPIService: MockAPIService!
// 1
var mockViewController: MockLaunchListViewController!