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
約9000個の自動テストの 時間を50分->10分に短縮 Flakyテストを1%以下に抑えた話
hatsu38
23
11k
Outline View in SwiftUI
1024jp
1
110
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
200
offers_20241022_imakiire.pdf
imakurusu
2
360
2万ページのSSG運用における工夫と注意点 / Vue Fes Japan 2024
chinen
3
1.3k
現場で役立つモデリング 超入門
masuda220
PRO
13
2.9k
リリース8年目のサービスの1800個のERBファイルをViewComponentに移行した方法とその結果
katty0324
5
3.6k
Golang と Erlang
taiyow
8
1.9k
Snowflake x dbtで作るセキュアでアジャイルなデータ基盤
tsoshiro
2
430
GitHub Actionsのキャッシュと手を挙げることの大切さとそれに必要なこと
satoshi256kbyte
5
390
PLoP 2024: The evolution of the microservice architecture pattern language
cer
PRO
0
1.6k
C#/.NETのこれまでのふりかえり
tomokusaba
1
160
Featured
See All Featured
The Art of Programming - Codeland 2020
erikaheidi
51
13k
How STYLIGHT went responsive
nonsquared
95
5.2k
Documentation Writing (for coders)
carmenintech
65
4.4k
The Power of CSS Pseudo Elements
geoffreycrofte
72
5.3k
A better future with KSS
kneath
238
17k
Become a Pro
speakerdeck
PRO
24
5k
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
46
2.1k
The Invisible Side of Design
smashingmag
297
50k
Building Adaptive Systems
keathley
38
2.2k
Making the Leap to Tech Lead
cromwellryan
132
8.9k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.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 • ӺใΛऔಘ͢Δ؆қͳΫϥΠΞϯτ • ࠓհͨ͠ςετΛஔ͍ͯ͋Γ·͢
͋Γ͕ͱ͏͍͟͝·ͨ͠