Exploring Automated Testing in Swift | by Apostolos Giokas | Jan, 2022

test pyramid base

Apostolos Geokas
public func addInt(_ a: Int, _ b: Int) -> Int {
a + b
}
func testAddInt() {
XCTAssertEqual(addInt(10, 20), 30)
XCTAssertEqual(addInt(-10, 20), 10)
XCTAssertEqual(addInt(-10, -20), -30)
}
func testAddInt_max() {
XCTAssertEqual(addInt(Int.max, 10), Int.max)
}
final class MyViewModelTests: XCTestCase {
var viewModel: MyViewModel? = nil
override func setUp() {
super.setUp()
viewModel = MyViewModel(persons: samplePersons(),
pets: samplePets())
}
init(datasource: DatasourceInterface = Datasource())
protocol UserDataStoreInterface {
func data(forKey defaultName: String) -> Data?
}
extension UserDefaults: UserDataStoreInterface {}
final class MyViewModel3 {
private let datasource: UserDataStoreInterface
init(datasource: UserDataStoreInterface) {
self.datasource = datasource
}
...
init(datasource: UserDataStoreInterface,
restclient: RestClient,
database: Database,
someUseCase: UseCase1,
someUseCase2: UseCase2,
webSocketClient: WSClient) {
...
}

Leave a Comment