multiplication(int: Int) -> Int { let base = UserDefaults.standard.integer(forKey: “base") return base * int } ςετِ࣌ʹࠩ͠ସ͍͑ͨ ελϒΛ͍͍ͨ ελϒΛ͑Δঢ়ଶʹ͢Δʂ େҬม͔Βऔಘ͍ͯ͠Δ
ReadableRepositoryContract) { self.repository = repository } func multiplication(int: Int) -> Int { let base = UserDefaults.standard.integer(forKey: “base") return base * int } } ᶅ҉తೖྗͷՕॴͰ1SPUPDPMΛར༻͢ΔΑ͏ʹมߋ͢Δ
ReadableRepositoryContract) { self.repository = repository } func multiplication(int: Int) -> Int { let base = UserDefaults.standard.integer(forKey: “base") return base * int } } ᶅ҉తೖྗͷՕॴͰ1SPUPDPMΛར༻͢ΔΑ͏ʹมߋ͢Δ
{ self.repository = repository } func multiplication(int: Int) -> Int { let base = self.repository.read() return base * int } } ελϒΛ͑Δঢ়ଶʹ͢Δ ᶅ҉తೖྗͷՕॴͰ1SPUPDPMΛར༻͢ΔΑ͏ʹมߋ͢Δ
5 let int = 2 let expected = 10 let repositoryStub = ReadableRepositoryStub(base: base) let input = Input(repository: repositoryStub) let actual = input.multiplication(int: int) XCTAssertEqual(actual, expected) } } ɾঢ়گJOU CBTFͷ࣌ ˙ ςετέʔε ɾظ͕ฦͬͯ͘Δ ελϒΛͬͯςετΛॻ͘ தͰελϒ͕ΘΕ͍ͯΔ