Created
April 16, 2018 08:55
-
-
Save popochess/97e574a0490417ca4fdaf9342568bda2 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
喔喔,好像有懂了,剛剛回頭看一篇之前講 swift mock 的,發現這個圖跟文章說的道理真的是一樣 | |
https://academy.realm.io/posts/tryswift-veronica-ray-real-world-mocking-swift/ | |
Stub : Fakes a response to method calls of an object 只是藉著 getVideoFor() 但最終不是要測它 | |
class StubTimeMachineAPI: TimeMachineAPI { | |
var videoUrl = "https://www.youtube.com/watch?v=SQ8aRKG9660" | |
func getVideoFor(year: Int) -> String { | |
return videoUrl | |
} | |
} | |
Mocks: Let you check if a method call is performed or if a property is set 最後是要測 timeTravelWasCalled 的值沒錯 | |
class MockTimeMachine: TimeMachine { | |
var timeTravelWasCalled = false | |
mutating func timeTravelTo(year: Int) { | |
timeTravelWasCalled = true | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment