Skip to content

Instantly share code, notes, and snippets.

@popochess
Created April 16, 2018 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save popochess/97e574a0490417ca4fdaf9342568bda2 to your computer and use it in GitHub Desktop.
Save popochess/97e574a0490417ca4fdaf9342568bda2 to your computer and use it in GitHub Desktop.
喔喔,好像有懂了,剛剛回頭看一篇之前講 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