venmo/DVR
소개
Swift용 네트워크 테스트
시스템 및 인프라측정된 스타 증가
- in 24h
- 0
- in 7 days
- 0
- in 15 days
- 0
- in 1 month
- 기록 수집 중
서로 겹치는 기간의 순증가량이며 일별 합계가 아닙니다. 측정값이 없으면 비워 둡니다. 스타는 관심도를 나타내며 품질을 보장하지 않습니다.
README.md
OriginalDVR
DVR is a simple Swift framework for making fake NSURLSession requests for iOS,
watchOS, and OS X based on VCR.
Easy dependency injection is the main design goal. The API is the same as NSURLSession. DVR.Session is a subclass of NSURLSession so you can use it as a drop in replacement anywhere. (Currently only data tasks are supported.)
Usage
let session = Session(cassetteName: "example")
let task = session.dataTask(with: request) { data, response, error in
// Do something with the response
}
// Nothing happens until you call `resume` as you'd expect.
task.resume()
This will playback the example cassette. The completion handler exactly the same way it normally would. In this example, DVR will look for a cassette named example.json in your test bundle.
If the recording of the request is missing, it will record and save it to disk. After saving to disk, it will assert with path of the recorded file. This causes the tests to stop so you can add the cassette to your test target and rerun your tests.
Recording Multiple Requests
By default, a DVR session only records one request. You can record multiple requests in the same cassette if you tell DVR when to start and stop recording.
let session = Session(cassetteName: "multiple")
// Begin recording multiple requests
session.beginRecording()
session.dataTask(with: URLRequest(url: URL(string: "http://apple.com")!)) { data, response, error in
// Do something with the response
session.dataTask(with: URLRequest(url: URL(string: "http://google.com")!)) { data, response, error in
// Do something with the response
}.resume()
// Finish recording multiple requests
session.endRecording() {
// All requests have completed
}
}.resume()
If you don't call beginRecording and endRecording, DVR will call these for your around the first request you make to a session. You can call endRecording immediately after you've submitted all of your requests to the session. The optional completion block that endRecording accepts will be called when all requests have finished. This is a good spot to fulfill XCTest expectations you've setup or do whatever else now that networking has finished.
관련 프로젝트 살펴보기
불러오는 중…