Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Getting started TDD on iOS Apps Development
Search
yashigani
February 15, 2014
Programming
0
1.3k
Getting started TDD on iOS Apps Development
Cocoa勉強会関西 #54 でTDDについて発表したときのスライドです.
yashigani
February 15, 2014
Tweet
Share
More Decks by yashigani
See All by yashigani
Hatena Engineer Seminar #10
yashigani
0
2.2k
Dependency Injection in iOS Apps
yashigani
2
460
Multiple layout with UITableViewCell
yashigani
1
3.4k
Lazy stored property
yashigani
3
2.1k
Code reviewing in iOS app development
yashigani
9
4.4k
Useful 3 techniques developing in iOS Apps
yashigani
0
1.5k
Introduction to WebKitPlus
yashigani
2
2.3k
Types in Swift
yashigani
5
2.3k
Swift with apps by Hatena
yashigani
13
29k
Other Decks in Programming
See All in Programming
CSC509 Lecture 13
javiergs
PRO
0
110
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
0
120
Kaigi on Rails 2024 〜運営の裏側〜
krpk1900
1
230
よくできたテンプレート言語として TypeScript + JSX を利用する試み / Using TypeScript + JSX outside of Web Frontend #TSKaigiKansai
izumin5210
6
1.7k
レガシーシステムにどう立ち向かうか 複雑さと理想と現実/vs-legacy
suzukihoge
14
2.2k
ふかぼれ!CSSセレクターモジュール / Fukabore! CSS Selectors Module
petamoriken
0
150
役立つログに取り組もう
irof
28
9.6k
どうして僕の作ったクラスが手続き型と言われなきゃいけないんですか
akikogoto
1
120
Make Impossible States Impossibleを 意識してReactのPropsを設計しよう
ikumatadokoro
0
230
3rd party scriptでもReactを使いたい! Preact + Reactのハイブリッド開発
righttouch
PRO
1
610
『ドメイン駆動設計をはじめよう』のモデリングアプローチ
masuda220
PRO
8
540
色々なIaCツールを実際に触って比較してみる
iriikeita
0
330
Featured
See All Featured
Happy Clients
brianwarren
98
6.7k
Intergalactic Javascript Robots from Outer Space
tanoku
269
27k
Making Projects Easy
brettharned
115
5.9k
Navigating Team Friction
lara
183
14k
Designing the Hi-DPI Web
ddemaree
280
34k
Building Applications with DynamoDB
mza
90
6.1k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Bash Introduction
62gerente
608
210k
The Cult of Friendly URLs
andyhume
78
6k
Designing Experiences People Love
moore
138
23k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
44
6.8k
Transcript
TDDΛ͡Ίͭͭ ࣄͷՌΛग़͢ํ๏ @yashigani
@yashigani • iOS/Mac Application Engineer • Fenrir Inc. • http://yashigani.hatenablog.com
• https://github.com/yashigani
εςοΧʔ͋͛·͢
agenda • TDDͱͳΜͧ • ͳͥςετΛॻ͘ͷ͔ • ςετΛॻ͘ͱ͘ͳΔʁ • ܦݧஊ •
BDD
TDD
Test Driven Development
ͳΜ͔ͦ͠͏ʂ
ͦΜͳ͜ͱແ͍ʂ
RED GREEN REFACTOR
Red Green Refactor • ςετΛॻ͍ͯམͪΔ͜ͱΛ֬ೝ • ςετ͕௨Δ࠷খݶͷ࣮͢Δ • ςετ͕௨ͬͨΒɼͦΕΛҡ࣋ͨ͠·· ϦϑΝΫλϦϯά
ͦΕ͚ͩͰ TDD͡ΊΒΕΔʂ
͏Ε͍͜͠ͱ • 1αΠΫϧऴΘΔͱඞͣςετ͕Δ • ࣍ͷมߋ࣌ʹ͜ΕΛͬͯɼطଘͷ࣮Λյ ͍ͯ͠ͳ͍͔֬ೝ͢Δ͜ͱ͕Ͱ͖Δ • ਓ͕ؒ୳͢ͱΊΜͲ͍͘͜͞ͱΛػցͤʹ • มߋ͍͢͠ίʔυʹͳΔ
ܕΛकΔ • ಛʹ1ͷαΠΫϧେࣄ • ͨ·ʹؒҧͬͨςετΛॻ͍͍ͯΔ͜ͱ͋Δ • ׳Ε͖ͯͨΒɼΓ͍͢Α͏ʹमਖ਼͢Δ • ͱݴͬͯΕ͕ͪ…͋·ΓؾΛམͱ͞ͳ͍
ͳͥςετΛॻ͘ͷ͔
ςετΛॻ͘ཧ༝ • ࣮ͷϨΠϠͰ༷Λ໌֬ʹ͢ΔͨΊ • ະདྷʹՃɾมߋ͢ΔͨΊ • ಈ࡞Λอূ͢ΔͨΊ • ࣮Λૣ͘ਐΊΔͨΊ
ςετΛॻ͘ͱ͘ͳΔ (͕૿͑Δ) ͷͰͳ͍͔ʁ
Ή͠Ζ͍߹͋Δ • ྫ͑APIΫϥΠΞϯτͷΑ͏ͳͷͷ࣮Λߟ ͑Δ • APIͱͷ௨৴෦Λॻ͍ͨ͋ͱͲ͏ͬͯಈ࡞֬ೝ Λ͢Δ͔ • UIΛ࡞͔ͬͯ֬ΊΔ •
σόοά࣮ߦͯ͠ΈΔ
UIΛ࡞͔ͬͯ֬ΊΔ • ͦͦUIͷ࣮ίετ͕ߴ͍ • ࢼ͢·Ͱʹ͕͔͔࣌ؒΔ • όάͷݪҼΓ͚͕େม(UI or ϩδοΫ) •
ࢼͤΔ͜Ζʹઈରͳʹ͔Ε͍ͯΔ
σόοά࣮ߦͯ͠ΈΔ • ͱΓ͋͑ͣίʔυͰݺͼग़ͯ͠Έͯɼࡉ͔͍͜ ͱlldb͔Βೖྗ͢Δ • ਓ͕ؒຖճ৺ΛࠐΊͯίϚϯυΛೖྗ͢Δඞཁ ແ͍ • ςετͳΒҰॻ͚ԿͰ܁Γฦ͑͠Δ
ςετΛॻ͖ͭͭ εϐʔυΛ্͛Δ • ಉ͜͡ͱΛ܁Γฦ͢ͳΒςετ͕͍ͯΔ • ಛʹCIͰͷࣗಈςετ • ςετΛॻ͘ՕॴΛߜΔ • ॻ͍ͨΒ͘ͳΔՕॴͳΒॻ͔ͳ͍
• ςετͷϦλʔϯΛߟྀ͢Δ
։ൃ͕͘ͳΔ߹ ੵۃతʹςετΛॻ͘ • ModelෳࡶͳॲཧΛ࣮͢Δ߹ • ٯʹViewͷςετίετʹ߹Θͳ͍߹͕ଟ͍ • Modelʹൺ༷มߋͷӨڹ͕ڧ͍ • Ͱ͖ͳ͍͜ͱແ͍
• ςετΛಋೖ͢ΔՕॴʹίετҙࣝΛ • ςετίʔυͳͷͰϝϯς͕ඞཁ
ಈ࡞Λ֬ೝ͢Δͷʹ͏ • ৽͍͠APIϥΠϒϥϦͷڍಈΛ֬ೝ͢Δͱ͖ʹ • NSURLSessionࢼ͍ͨ͠ɼMantleࢼ͍ͨ͠ • ςετʹ͓ͯͯ͘͠͠ͱޙʑ͑Δ • OS ver͝ͱͷڍಈͷҧ͍Λݕূͨ͠Γ
• αʔόΛStubͱຊ൪ΛΓସ͑ͯ…ͳͲ
ܦݧஊ (ࣦഊஊ)
ςετ͕ಈ͔ͳ͘ͳͬͨ·· ์ஔ͍ͯͨ͠ • ςετ͕ಈ͔ͳ͘ͳ͍͕ͬͯͨ͞ͳ͔ͬͨ • CIͷςετ࣮ߦͷδϣϒεΫϦϓτͷ࣮ߦͷΈ Λআɼδϣϒͦͷ·· • ͦͷޙಈ͔ͳͨ͘͠ࣄ࣮ΛΕͯ͠·͍ɼςε τ͕࣮ߦ͞Ε͍ͯͳ͔ͬͨঢ়ଶͩͬͨ
• ਖ਼͘͠ಈ͘ςετΛҡ࣋͢Δ
ॻ͍͔ͨ͠௨Βͳ͍ςετ Λॻ͍͍ͯͨ • աڈ30ͷϩάͷΈ͢ɼͱ͍͏ػೳͷςετΛ ॻ͍͍ͯͨͱ͖ɼςετσʔλΛಛఆͷ͔Β 100Ճͨ͠ • ࣍ͷࢼ͢ͱςετ͕མͪΔΑ͏ʹͳ͍ͬͯͨ • ܧଓతʹςετΛ࣮ߦ͢Δඞཁੑ
ςετॻ͘ͷίετ • ಛʹෳࡶͳσʔλΛ࡞Δඞཁͷ͋Δςετॻ ͘ͷ͕ΊΜͲ͍͘͞ • Α͘Α͘ߟ͑Δͱɼςετॻ͔ͳ͍΄͏͕σόο ά͕ΊΜͲ͍͘͞ • ςετΛॻ͘ίετ <
खಈͰςετ͢Δίετ
ͦͷ΄͔ྑ͍ͱײ͡Δ͜ͱ • ΤϥʔέʔεΛ࡞Δͷ͕Χϯλϯ • ෳࡶͳཁ݅Λঃʑʹ࣮͍ͯ͘͠ͷ͕༰қ • ςετ࣮ߦ࣌ʹϒϨʔΫϙΠϯτΛઃఆͰ͖Δ
BDD
Driven Development
BDD • Behavior Driven Development • TDDͷςετΛΑΓཁٻ༷ʹ͍ۙܗͰදݱ • RSpecͱ͔Cucumberͱ͔ •
ࣗવݴޠͬΆ͕͋ͬͯ͞ΧϫΠΠ
BDD framework • Kiwi • https://github.com/allending/Kiwi • Specta • https://github.com/specta/specta
- (void)testHREClient { TRVSMonitor *monitor = TRVSMonitor.monitor; [_client getStations:@"৽॓" completionHandler:^(NSArray
*res, NSError *e) { XCTAssertNil(e, @":("); XCTAssertNotNil(res, @":("); [monitor signal]; }]; [monitor wait]; ! [_client getStations:@"ైԦொ" completionHandler:^(NSArray *res, NSError *e) { XCTAssertNotNil(e, @":("); XCTAssertNotNil(e.userInfo[@"error"], @":("); XCTAssertNil(res, @":("); [monitor signal]; }]; [monitor wait]; }
it(@“should found stations", ^{! TRVSMonitor *monitor = TRVSMonitor.monitor;! [client getStations:@"৽॓"!
completionHandler:^(NSArray *res, NSError *e) {! [[e should] beNil];! [[res should] beNonNil];! [monitor signal];! }];! [monitor wait];! });! it(@“should not found stations", ^{! TRVSMonitor *monitor = TRVSMonitor.monitor;! [client getStations:@"ైԦொ"! completionHandler:^(NSArray *res, NSError *e) {! [[e should] beNonNil];! [[e.userInfo[@"error"] should] beNonNil];! [[res should] beNil];! [monitor signal];! }];! [monitor wait];! });
it(@"should found stations", ^AsyncBlock {! [client getStations:@"৽॓"! completionHandler:^(NSArray *res, NSError
*e) {! expect(e).to.beNil();! expect(res).notTo.beNil();! done();! }];! });! it(@"should not found stations", ^AsyncBlock {! [client getStations:@"ైԦொ"! completionHandler:^(NSArray *res, NSError *e) {! expect(e).notTo.beNil();! expect(e.userInfo[@"error"]).notTo.beNil();! expect(res).to.beNil();! done();! }];! });
vs. XCTest/SenTestingKit • ͏ͷʹηοτΞοϓ͕ඞཁ • ͨͩ͠CocoaPodsͬͯΔ߹༨༟ • ϝιου୯ҐͰ࣮ߦͰ͖ͳ͍ • ѹతʹՄಡੑ͕ߴ͍
·ͱΊ • ίετΛߟྀͭͭ͠ແཧͤͣಋೖ͢ΔͱΑ͍ • ΔͳΒઈରʹCI·Ͱ(͘͠ܧଓతʹ࣮ߦ͠ ͍͢ڥΛ࡞Δ) • ҙࣝߴΊͯ1िؒ͘Β͍ͬͯΈͨΒʹ͔ͭ͘ Βɼ͡ΊΔͳΒҙࣝߴ·ͬͨࠓʂ
ࢀߟ • https://github.com/yashigani/HREClient • ӺใΛऔಘ͢Δ؆қͳΫϥΠΞϯτ • ࠓհͨ͠ςετΛஔ͍ͯ͋Γ·͢
͋Γ͕ͱ͏͍͟͝·ͨ͠