Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.


📦
📦




























import Alamofire
import Mockingjay
import Quick
import Nimble
@testable import Hoge
class HogeSpec: QuickSpec {
override func spec() {
describe("hoge") {
context("fuga") {
it("piyo") {
}
}
}
}
}
context("fuga") {
beforeEach {
self.stub({ request in
return request.url?.host == "hogefugapiyo.com"
}, { request in
let r...
it("piyo") {
let request = Alamofire.request("https://hogefugapiyo.com")
var expectation: Any? = nil
waitUntil { done in
r...










Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Upcoming SlideShare
Loading in …5
×

Stubる - Mockingjayを使ったHTTPクライアントのテスト -

1,290 views

Published on

iOS Test Night #4での登壇資料です。
https://testnight.connpass.com/event/54316/

Published in: Technology
  • Be the first to comment

Stubる - Mockingjayを使ったHTTPクライアントのテスト -

  1. 1. 

  2. 2. 📦
  3. 3. 📦
  4. 4. 
 
 
 

  5. 5. 
 
 
 
 
 
 

  6. 6. 
 
 

  7. 7. import Alamofire import Mockingjay import Quick import Nimble @testable import Hoge
  8. 8. class HogeSpec: QuickSpec { override func spec() { describe("hoge") { context("fuga") { it("piyo") { } } } } }
  9. 9. context("fuga") { beforeEach { self.stub({ request in return request.url?.host == "hogefugapiyo.com" }, { request in let response = HTTPURLResponse( url: request.url!, statusCode: 200, httpVersion: nil, headerFields: nil) let path = Bundle(for: type(of: self)) .path(forResource: "piyo", ofType: "json")! let url = URL(fileURLWithPath: path) let data = try! Data(contentsOf: url) return .success(response!, .content(data)) }) } }
  10. 10. it("piyo") { let request = Alamofire.request("https://hogefugapiyo.com") var expectation: Any? = nil waitUntil { done in request.responseJSON { response in switch response.result { case .success(let json): expectation = json print("success: (json)") case .failure(let error): print("failure: (error)") } expect(expectation).toNot(beNil()) done() } } }
  11. 11. 
 

  12. 12. 
 
 


×