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
OSSで起業してもうすぐ10年 / Open Source Conference 2024 Shimane
furukawayasuto
0
100
アジャイルを支えるテストアーキテクチャ設計/Test Architecting for Agile
goyoki
9
3.3k
3 Effective Rules for Using Signals in Angular
manfredsteyer
PRO
1
100
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.1k
OnlineTestConf: Test Automation Friend or Foe
maaretp
0
110
Enabling DevOps and Team Topologies Through Architecture: Architecting for Fast Flow
cer
PRO
0
330
Macとオーディオ再生 2024/11/02
yusukeito
0
370
見せてあげますよ、「本物のLaravel批判」ってやつを。
77web
7
7.7k
What’s New in Compose Multiplatform - A Live Tour (droidcon London 2024)
zsmb
1
470
Click-free releases & the making of a CLI app
oheyadam
2
120
.NET のための通信フレームワーク MagicOnion 入門 / Introduction to MagicOnion
mayuki
1
1.5k
役立つログに取り組もう
irof
28
9.6k
Featured
See All Featured
Navigating Team Friction
lara
183
14k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
It's Worth the Effort
3n
183
27k
Building Your Own Lightsaber
phodgson
103
6.1k
Building Applications with DynamoDB
mza
90
6.1k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.4k
Being A Developer After 40
akosma
86
590k
Designing for Performance
lara
604
68k
GraphQLとの向き合い方2022年版
quramy
43
13k
BBQ
matthewcrist
85
9.3k
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 • ӺใΛऔಘ͢Δ؆қͳΫϥΠΞϯτ • ࠓհͨ͠ςετΛஔ͍ͯ͋Γ·͢
͋Γ͕ͱ͏͍͟͝·ͨ͠