SlideShare a Scribd company logo


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




























Stubる - Mockingjayを使ったHTTPクライアントのテスト -
Stubる - Mockingjayを使ったHTTPクライアントのテスト -
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 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))
})
}
}
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()
}
}
}










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

More Related Content

PDF
Java libraries you can't afford to miss
Andres Almiray
 
PPTX
Kotlin is charming; The reasons Java engineers should start Kotlin.
JustSystems Corporation
 
PDF
Introduction kot iin
Jedsada Tiwongvokul
 
PDF
JJUG CCC 2011 Spring
Kiyotaka Oku
 
PDF
Jggug 2010 330 Grails 1.3 観察
Tsuyoshi Yamamoto
 
PDF
The report of JavaOne2011 about groovy
Yasuharu Nakano
 
PDF
Boom! Promises/A+ Was Born
Domenic Denicola
 
PDF
Spock: A Highly Logical Way To Test
Howard Lewis Ship
 
Java libraries you can't afford to miss
Andres Almiray
 
Kotlin is charming; The reasons Java engineers should start Kotlin.
JustSystems Corporation
 
Introduction kot iin
Jedsada Tiwongvokul
 
JJUG CCC 2011 Spring
Kiyotaka Oku
 
Jggug 2010 330 Grails 1.3 観察
Tsuyoshi Yamamoto
 
The report of JavaOne2011 about groovy
Yasuharu Nakano
 
Boom! Promises/A+ Was Born
Domenic Denicola
 
Spock: A Highly Logical Way To Test
Howard Lewis Ship
 

What's hot (20)

PDF
#살아있다 #자프링외길12년차 #코프링2개월생존기
Arawn Park
 
PDF
Jason parsing
parallelminder
 
PPTX
Python and EM CLI: The Enterprise Management Super Tools
Seth Miller
 
PDF
Web Crawling with NodeJS
Sylvain Zimmer
 
PDF
Miracle of std lib
Jedsada Tiwongvokul
 
PPTX
What’s new in C# 6
Fiyaz Hasan
 
PPTX
The Promised Land (in Angular)
Domenic Denicola
 
PPTX
Async Frontiers
Domenic Denicola
 
KEY
Python在豆瓣的应用
Qiangning Hong
 
PDF
Grails/Groovyによる開発事例紹介
Kiyotaka Oku
 
PDF
OneRing @ OSCamp 2010
Qiangning Hong
 
PDF
Testing Backbone applications with Jasmine
Leon van der Grient
 
KEY
groovy & grails - lecture 2
Alexandre Masselot
 
PPTX
Spock
Evgeny Borisov
 
PDF
Auto-GWT : Better GWT Programming with Xtend
Sven Efftinge
 
PDF
History of jQuery
jeresig
 
PPTX
Ian 20150116 java script oop
LearningTech
 
KEY
Gwt and Xtend
Sven Efftinge
 
PDF
Spock Testing Framework - The Next Generation
BTI360
 
PDF
Asynchronous programming done right - Node.js
Piotr Pelczar
 
#살아있다 #자프링외길12년차 #코프링2개월생존기
Arawn Park
 
Jason parsing
parallelminder
 
Python and EM CLI: The Enterprise Management Super Tools
Seth Miller
 
Web Crawling with NodeJS
Sylvain Zimmer
 
Miracle of std lib
Jedsada Tiwongvokul
 
What’s new in C# 6
Fiyaz Hasan
 
The Promised Land (in Angular)
Domenic Denicola
 
Async Frontiers
Domenic Denicola
 
Python在豆瓣的应用
Qiangning Hong
 
Grails/Groovyによる開発事例紹介
Kiyotaka Oku
 
OneRing @ OSCamp 2010
Qiangning Hong
 
Testing Backbone applications with Jasmine
Leon van der Grient
 
groovy & grails - lecture 2
Alexandre Masselot
 
Auto-GWT : Better GWT Programming with Xtend
Sven Efftinge
 
History of jQuery
jeresig
 
Ian 20150116 java script oop
LearningTech
 
Gwt and Xtend
Sven Efftinge
 
Spock Testing Framework - The Next Generation
BTI360
 
Asynchronous programming done right - Node.js
Piotr Pelczar
 
Ad

More from Kenji Tanaka (20)

PDF
FatViewControllerを安全に書き換える方法が見つからなかったので、どういう痛みを許容するか考えた #iosdc
Kenji Tanaka
 
PDF
リリース前のリグレッションテストがめんどい!のでMagic PodでUIテストを試してみる #pixiv_app_night
Kenji Tanaka
 
PDF
ポストモーテムやってみた #yjbonfire
Kenji Tanaka
 
PDF
2つの同期 4つの状態 #pixiv_ios_arch
Kenji Tanaka
 
PDF
2つの同期 4つの状態 #app_mp
Kenji Tanaka
 
PDF
2つの同期 4つの状態 #roppongiswift
Kenji Tanaka
 
PDF
トークンリフレッシュ処理を含むAPIClientのテスト #hakata_test_night
Kenji Tanaka
 
PDF
よく使うテストヘルパーの紹介 #ios_test_night
Kenji Tanaka
 
PDF
Swiftで聞いておぼえるテスト書き
Kenji Tanaka
 
PDF
設計時空のリファクタリング
Kenji Tanaka
 
PDF
WACATE 2018 Summer
Kenji Tanaka
 
PDF
テスト駆動開発入門 by Swift
Kenji Tanaka
 
PDF
An iOS Engineer challenges Web.
Kenji Tanaka
 
PDF
エンジニアのためのブログ講座Ver4
Kenji Tanaka
 
PDF
TDDやってみよ
Kenji Tanaka
 
PDF
ストレス社会に生きる、iOSエンジニアにオススメする百合の世界と作品
Kenji Tanaka
 
PDF
節子、それViewControllerやない...、FatViewControllerや...。
Kenji Tanaka
 
PDF
iOS 11からのDeviceCheck #とは
Kenji Tanaka
 
PDF
設計に答えはないから探してみよう
Kenji Tanaka
 
PDF
iOS 11からのアプリ間ファイル共有
Kenji Tanaka
 
FatViewControllerを安全に書き換える方法が見つからなかったので、どういう痛みを許容するか考えた #iosdc
Kenji Tanaka
 
リリース前のリグレッションテストがめんどい!のでMagic PodでUIテストを試してみる #pixiv_app_night
Kenji Tanaka
 
ポストモーテムやってみた #yjbonfire
Kenji Tanaka
 
2つの同期 4つの状態 #pixiv_ios_arch
Kenji Tanaka
 
2つの同期 4つの状態 #app_mp
Kenji Tanaka
 
2つの同期 4つの状態 #roppongiswift
Kenji Tanaka
 
トークンリフレッシュ処理を含むAPIClientのテスト #hakata_test_night
Kenji Tanaka
 
よく使うテストヘルパーの紹介 #ios_test_night
Kenji Tanaka
 
Swiftで聞いておぼえるテスト書き
Kenji Tanaka
 
設計時空のリファクタリング
Kenji Tanaka
 
WACATE 2018 Summer
Kenji Tanaka
 
テスト駆動開発入門 by Swift
Kenji Tanaka
 
An iOS Engineer challenges Web.
Kenji Tanaka
 
エンジニアのためのブログ講座Ver4
Kenji Tanaka
 
TDDやってみよ
Kenji Tanaka
 
ストレス社会に生きる、iOSエンジニアにオススメする百合の世界と作品
Kenji Tanaka
 
節子、それViewControllerやない...、FatViewControllerや...。
Kenji Tanaka
 
iOS 11からのDeviceCheck #とは
Kenji Tanaka
 
設計に答えはないから探してみよう
Kenji Tanaka
 
iOS 11からのアプリ間ファイル共有
Kenji Tanaka
 
Ad

Recently uploaded (20)

PPTX
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
PDF
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
PDF
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
PPTX
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
PPTX
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
PPTX
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
PDF
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
PDF
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
PDF
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
PDF
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
PDF
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
PPTX
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
PDF
The Future of Artificial Intelligence (AI)
Mukul
 
PDF
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
PDF
Brief History of Internet - Early Days of Internet
sutharharshit158
 
PDF
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
PDF
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
PPTX
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 
The-Ethical-Hackers-Imperative-Safeguarding-the-Digital-Frontier.pptx
sujalchauhan1305
 
Make GenAI investments go further with the Dell AI Factory
Principled Technologies
 
A Strategic Analysis of the MVNO Wave in Emerging Markets.pdf
IPLOOK Networks
 
Agile Chennai 18-19 July 2025 Ideathon | AI Powered Microfinance Literacy Gui...
AgileNetwork
 
AI in Daily Life: How Artificial Intelligence Helps Us Every Day
vanshrpatil7
 
IT Runs Better with ThousandEyes AI-driven Assurance
ThousandEyes
 
AI Unleashed - Shaping the Future -Starting Today - AIOUG Yatra 2025 - For Co...
Sandesh Rao
 
MASTERDECK GRAPHSUMMIT SYDNEY (Public).pdf
Neo4j
 
CIFDAQ's Market Wrap : Bears Back in Control?
CIFDAQ
 
AI-Cloud-Business-Management-Platforms-The-Key-to-Efficiency-Growth.pdf
Artjoker Software Development Company
 
Oracle AI Vector Search- Getting Started and what's new in 2025- AIOUG Yatra ...
Sandesh Rao
 
Dev Dives: Automate, test, and deploy in one place—with Unified Developer Exp...
AndreeaTom
 
The Future of Artificial Intelligence (AI)
Mukul
 
Economic Impact of Data Centres to the Malaysian Economy
flintglobalapac
 
Brief History of Internet - Early Days of Internet
sutharharshit158
 
Research-Fundamentals-and-Topic-Development.pdf
ayesha butalia
 
Structs to JSON: How Go Powers REST APIs
Emily Achieng
 
Applied-Statistics-Mastering-Data-Driven-Decisions.pptx
parmaryashparmaryash
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
GDG Cloud Munich - Intro - Luiz Carneiro - #BuildWithAI - July - Abdel.pdf
Luiz Carneiro
 

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

  • 1.
  • 10. import Alamofire import Mockingjay import Quick import Nimble @testable import Hoge
  • 11. class HogeSpec: QuickSpec { override func spec() { describe("hoge") { context("fuga") { it("piyo") { } } } } }
  • 12. 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)) }) } }
  • 13. 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() } } }