SlideShare a Scribd company logo
1 of 12
Download to read offline
2018/12/10 iOS Test Night #9 2 #ios_test_night
(@ktanaka117)
• / @ktanaka117
•
• :
• R&D Swift TDD
• PEAKS iOS
• …
•
• :
Json 🤔
let hogeURL = Bundle(for: type(of: self))
.url(forResource: "Hoge", withExtension: "json")!
let data = try! Data(contentsOf: hogeURL)
let decoder = JSONDecoder()
let hoge = try! decoder.decode(Hoge.self, from: data)
hoge Stub hoge 

Json 😄


hoge
let hoge: Hoge = TestDataHelper
.testData(forResource: "Hoge", ofType: "json")
Json -
class TestDataHelper {
static func testData<T: Decodable>(forResource resource: String, ofType type: String) -> T {
let url = Bundle(for: TestDataHelper.self).url(forResource: resource, withExtension: type)!
let data = try! Data(contentsOf: url)
let decoder = JSONDecoder()
return try! decoder.decode(T.self, from: data)
}
}
Response HTTP Stub🤔
var responses = [authError, successWithAccessToken, success]

stub(condition: isHost("example.com")) { request in
return responses.removeFirst()
}
// ......
// ...
OHHTTPStubs.removeAllStubs()
responses test function …
Response HTTP Stub😄
HTTPStub.activate(
condition: isHost("example.com"),
responses: [authError, successWithAccessToken, success])
// ......
// ...
HTTPStub.deactivate()
responses
Response HTTP Stub -
struct HTTPStub {
static func activate(condition: @escaping OHHTTPStubsTestBlock,
responses: [OHHTTPStubsResponse]) {
var responsesArray = responses
stub(condition: condition) { request in
let response = responsesArray.removeFirst()
return response
}
}
static func deactivate() {
OHHTTPStubs.removeAllStubs()
}
}
:
•
•
•
•
12/14 in 

APIClient 

2019/01/15 in pixiv Inc.

iOS

More Related Content

What's hot

Golang slidesaudrey
Golang slidesaudreyGolang slidesaudrey
Golang slidesaudrey
Audrey Lim
 
Elasticsearch And Ruby [RuPy2012]
Elasticsearch And Ruby [RuPy2012]Elasticsearch And Ruby [RuPy2012]
Elasticsearch And Ruby [RuPy2012]
Karel Minarik
 

What's hot (20)

Productive Programming in Groovy
Productive Programming in GroovyProductive Programming in Groovy
Productive Programming in Groovy
 
Node collaboration - Exported Resources and PuppetDB
Node collaboration - Exported Resources and PuppetDBNode collaboration - Exported Resources and PuppetDB
Node collaboration - Exported Resources and PuppetDB
 
Large Scale Log Analytics with Solr (from Lucene Revolution 2015)
Large Scale Log Analytics with Solr (from Lucene Revolution 2015)Large Scale Log Analytics with Solr (from Lucene Revolution 2015)
Large Scale Log Analytics with Solr (from Lucene Revolution 2015)
 
ElasticSearch for .NET Developers
ElasticSearch for .NET DevelopersElasticSearch for .NET Developers
ElasticSearch for .NET Developers
 
Elasticsearch & "PeopleSearch"
Elasticsearch & "PeopleSearch"Elasticsearch & "PeopleSearch"
Elasticsearch & "PeopleSearch"
 
Postgresql search demystified
Postgresql search demystifiedPostgresql search demystified
Postgresql search demystified
 
Webinar: Index Tuning and Evaluation
Webinar: Index Tuning and EvaluationWebinar: Index Tuning and Evaluation
Webinar: Index Tuning and Evaluation
 
Lucene
LuceneLucene
Lucene
 
Golang slidesaudrey
Golang slidesaudreyGolang slidesaudrey
Golang slidesaudrey
 
The Ring programming language version 1.6 book - Part 42 of 189
The Ring programming language version 1.6 book - Part 42 of 189The Ring programming language version 1.6 book - Part 42 of 189
The Ring programming language version 1.6 book - Part 42 of 189
 
Full Text Search In PostgreSQL
Full Text Search In PostgreSQLFull Text Search In PostgreSQL
Full Text Search In PostgreSQL
 
Elastic search 검색
Elastic search 검색Elastic search 검색
Elastic search 검색
 
Hacking Lucene for Custom Search Results
Hacking Lucene for Custom Search ResultsHacking Lucene for Custom Search Results
Hacking Lucene for Custom Search Results
 
아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문아파트 정보를 이용한 ELK stack 활용 - 오근문
아파트 정보를 이용한 ELK stack 활용 - 오근문
 
Avro introduction
Avro introductionAvro introduction
Avro introduction
 
ElasticSearch: Найдется все... и быстро!
ElasticSearch: Найдется все... и быстро!ElasticSearch: Найдется все... и быстро!
ElasticSearch: Найдется все... и быстро!
 
Azure search
Azure searchAzure search
Azure search
 
Elasticsearch And Ruby [RuPy2012]
Elasticsearch And Ruby [RuPy2012]Elasticsearch And Ruby [RuPy2012]
Elasticsearch And Ruby [RuPy2012]
 
Elasticsearch in 15 Minutes
Elasticsearch in 15 MinutesElasticsearch in 15 Minutes
Elasticsearch in 15 Minutes
 
Interfaces to xapian
Interfaces to xapianInterfaces to xapian
Interfaces to xapian
 

Similar to よく使うテストヘルパーの紹介 #ios_test_night

CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
Sven Haiges
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
Mario Fusco
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02
Ramamohan Chokkam
 

Similar to よく使うテストヘルパーの紹介 #ios_test_night (20)

CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Lucene Introduction
Lucene IntroductionLucene Introduction
Lucene Introduction
 
Json the-x-in-ajax1588
Json the-x-in-ajax1588Json the-x-in-ajax1588
Json the-x-in-ajax1588
 
Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
 
Webinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDBWebinar: Simplifying Persistence for Java and MongoDB
Webinar: Simplifying Persistence for Java and MongoDB
 
Beautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with IonBeautiful REST+JSON APIs with Ion
Beautiful REST+JSON APIs with Ion
 
Simplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with MorphiaSimplifying Persistence for Java and MongoDB with Morphia
Simplifying Persistence for Java and MongoDB with Morphia
 
Elasticsearch - Zero to Hero
Elasticsearch - Zero to HeroElasticsearch - Zero to Hero
Elasticsearch - Zero to Hero
 
Designing a beautiful REST json api
Designing a beautiful REST json apiDesigning a beautiful REST json api
Designing a beautiful REST json api
 
RESTing with the new Yandex.Disk API, Clemens Аuer
RESTing with the new Yandex.Disk API, Clemens АuerRESTing with the new Yandex.Disk API, Clemens Аuer
RESTing with the new Yandex.Disk API, Clemens Аuer
 
Crafting Evolvable Api Responses
Crafting Evolvable Api ResponsesCrafting Evolvable Api Responses
Crafting Evolvable Api Responses
 
Java 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forwardJava 7, 8 & 9 - Moving the language forward
Java 7, 8 & 9 - Moving the language forward
 
Beautiful REST and JSON APIs - Les Hazlewood
Beautiful REST and JSON APIs - Les HazlewoodBeautiful REST and JSON APIs - Les Hazlewood
Beautiful REST and JSON APIs - Les Hazlewood
 
Володимир Гоцик. Getting maximum of python, django with postgres 9.4. PyCon B...
Володимир Гоцик. Getting maximum of python, django with postgres 9.4. PyCon B...Володимир Гоцик. Getting maximum of python, django with postgres 9.4. PyCon B...
Володимир Гоцик. Getting maximum of python, django with postgres 9.4. PyCon B...
 
Fast track to lucene
Fast track to luceneFast track to lucene
Fast track to lucene
 
Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02Jsonsaga 100605143125-phpapp02
Jsonsaga 100605143125-phpapp02
 
Examiness hints and tips from the trenches
Examiness hints and tips from the trenchesExaminess hints and tips from the trenches
Examiness hints and tips from the trenches
 
Elasticsearch: You know, for search! and more!
Elasticsearch: You know, for search! and more!Elasticsearch: You know, for search! and more!
Elasticsearch: You know, for search! and more!
 
Json to hive_schema_generator
Json to hive_schema_generatorJson to hive_schema_generator
Json to hive_schema_generator
 
MongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in BavariaMongoDB Munich 2012: MongoDB for official documents in Bavaria
MongoDB Munich 2012: MongoDB for official documents in Bavaria
 

More from Kenji Tanaka

リリース前のリグレッションテストがめんどい!のでMagic PodでUIテストを試してみる #pixiv_app_night
リリース前のリグレッションテストがめんどい!のでMagic PodでUIテストを試してみる #pixiv_app_nightリリース前のリグレッションテストがめんどい!のでMagic PodでUIテストを試してみる #pixiv_app_night
リリース前のリグレッションテストがめんどい!のでMagic PodでUIテストを試してみる #pixiv_app_night
Kenji Tanaka
 

More from Kenji Tanaka (20)

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

Recently uploaded

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
WSO2
 

Recently uploaded (20)

presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
WSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering DevelopersWSO2's API Vision: Unifying Control, Empowering Developers
WSO2's API Vision: Unifying Control, Empowering Developers
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Platformless Horizons for Digital Adaptability
Platformless Horizons for Digital AdaptabilityPlatformless Horizons for Digital Adaptability
Platformless Horizons for Digital Adaptability
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

よく使うテストヘルパーの紹介 #ios_test_night

  • 1. 2018/12/10 iOS Test Night #9 2 #ios_test_night (@ktanaka117)
  • 2. • / @ktanaka117 • • : • R&D Swift TDD • PEAKS iOS
  • 4. Json 🤔 let hogeURL = Bundle(for: type(of: self)) .url(forResource: "Hoge", withExtension: "json")! let data = try! Data(contentsOf: hogeURL) let decoder = JSONDecoder() let hoge = try! decoder.decode(Hoge.self, from: data) hoge Stub hoge 

  • 5. Json 😄 
 hoge let hoge: Hoge = TestDataHelper .testData(forResource: "Hoge", ofType: "json")
  • 6. Json - class TestDataHelper { static func testData<T: Decodable>(forResource resource: String, ofType type: String) -> T { let url = Bundle(for: TestDataHelper.self).url(forResource: resource, withExtension: type)! let data = try! Data(contentsOf: url) let decoder = JSONDecoder() return try! decoder.decode(T.self, from: data) } }
  • 7. Response HTTP Stub🤔 var responses = [authError, successWithAccessToken, success]
 stub(condition: isHost("example.com")) { request in return responses.removeFirst() } // ...... // ... OHHTTPStubs.removeAllStubs() responses test function …
  • 8. Response HTTP Stub😄 HTTPStub.activate( condition: isHost("example.com"), responses: [authError, successWithAccessToken, success]) // ...... // ... HTTPStub.deactivate() responses
  • 9. Response HTTP Stub - struct HTTPStub { static func activate(condition: @escaping OHHTTPStubsTestBlock, responses: [OHHTTPStubsResponse]) { var responsesArray = responses stub(condition: condition) { request in let response = responsesArray.removeFirst() return response } } static func deactivate() { OHHTTPStubs.removeAllStubs() } }
  • 12. 2019/01/15 in pixiv Inc.
 iOS