HTTPMock
μ HTTP νΈμΆ μ κ°μ§ λ°μ΄ν°λ₯Ό λ€μ΄λ‘λλ°μ μ μλλ‘ ν΄μ£Όλ λΌμ΄λΈλ¬λ¦¬μ
λλ€.
λ€νΈμν¬ νΈμΆμ΄ νμν μ±μ μλ² μμ΄ μ λ ν
μ€νΈν λ μ μ©νκ² μΈ μ μμ΅λλ€.
URLSession
μ¬μ© μ stubλ λ°μ΄ν°λ₯Ό λ°μ μ μλλ‘ νκΈ° μν΄μλ URLSessionConfiguration.protocolClasses
μ
custom classλ₯Ό λ±λ‘ν΄μΌ ν©λλ€. λ±λ‘νλ λ°©λ²μΌλ‘λ μλ μΈ κ°μ§κ° μμ΅λλ€.
URLSessionConfiguration
μ μ§μ λ±λ‘νλ λ°©λ²μ
λλ€.
let configuration = URLSessionConfiguration.default
URLProtocolService.registerStub(in: configuration)
let session = URLSession(configuration: configuration)
...
URLSessionConfiguration
μμ± μ μλμΌλ‘ λ±λ‘νκ³ μΆλ€λ©΄ μλμ λ©μλλ₯Ό μ¬μ©ν©λλ€.
URLProtocolService.registerStubInDefaultConfiguration()
let configuration = URLSessionConfiguration.default
let session = URLSession(configuration: configuration)
...
URLSession
μ μμ± ν configuration
λ³κ²½μ΄ λΆκ°λ₯ν©λλ€. λ°λΌμ URLSession.shared
λ₯Ό μ¬μ©νλ€λ©΄ μλμ λ©μλλ₯Ό νΈμΆν΄μΌ ν©λλ€.
URLProtocolService.registerStubInSharedSession()
λ±λ‘μ ν΄μ νκ³ μΆλ€λ©΄ μλμ λ©μλλ₯Ό μ¬μ©ν©λλ€.
URLProtocolService.unregisterStub(from: configuration)
URLProtocolService.unregisterStubFromDefaultConfiguration()
URLProtocolService.unregisterStubFromEphemeralConfiguration()
URLProtocolService.unregisterStubFromSharedSession()
let bundle = Bundle(for: type(of: self))
let responseFileURL = bundle.url(forResource: "items", withExtension: "json")!
stub(when: .isHost("server.com"), then: .fileURL(responseFileURL))
// stub μ λ€μν μ€μ κ°λ₯. ex) 2μ΄ λλ μ΄ ν 1KBμ© μ μ‘
stub(when: .isHost("server.com") && .hasLastPathComponent("items.json"),
then: .fileURL(responseFileURL)
.settingResponseDelay(2.0)
.settingPreferredBytesPerSecond(1_000))
μμ μκ΄μμ΄ μ λ μμ
μ ν ν URLSession.dataTask(with:)
λ URLSession.downloadTask(with:)
λ₯Ό νΈμΆνλ©΄ stubλ λ°μ΄ν°λ₯Ό μ»μ μ μμ΅λλ€.
.package(url: "https://github.com/nearfri/HTTPMock", from: "0.9.0")
link |
Stars: 0 |
Last commit: 1 year ago |
Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics