Skip to content

Instantly share code, notes, and snippets.

@cipolleschi
Last active April 18, 2020 19:31
Show Gist options
  • Select an option

  • Save cipolleschi/98ce370b355a80dad18b6dcacdae6fa0 to your computer and use it in GitHub Desktop.

Select an option

Save cipolleschi/98ce370b355a80dad18b6dcacdae6fa0 to your computer and use it in GitHub Desktop.
Test by using protocols
import XCTest
import Foundation
/// File manager stub to override the methods we need
class FileManagerStub: AppFileManager {
func getContent(atPath: Stirng) -> Data? {
return Data()
}
}
/// Class under test
class MyViewControllerTest: XCTestCase {
func testLoadContent_withEmptyFile() {
let vc = MyViewController()
let fileManagerStub = FileManagerStub()
let decoder: JSONDecoder = JSONDecoder()
vc.loadContent(fileManager: fileManagerStub, path: "emptyFile", jsonDecoder: decoder)
XCTAssertTrue(vc.content.isEmpty)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment