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
Generative AI Use Cases JP (略称:GenU)奮闘記
hideg
0
150
Why Spring Matters to Jakarta EE - and Vice Versa
ivargrimstad
0
980
推し活としてのrails new/oshikatsu_ha_iizo
sakahukamaki
3
1.7k
WEBエンジニア向けAI活用入門
sutetotanuki
0
300
ピラミッド、アイスクリームコーン、SMURF: 自動テストの最適バランスを求めて / Pyramid Ice-Cream-Cone and SMURF
twada
PRO
9
1k
Amazon Neptuneで始めてみるグラフDB-OpenSearchによるグラフの全文検索-
satoshi256kbyte
4
330
Vue SFCのtemplateでTypeScriptの型を活用しよう
tsukkee
3
1.5k
Java ジェネリクス入門 2024
nagise
0
600
LLM生成文章の精度評価自動化とプロンプトチューニングの効率化について
layerx
PRO
2
140
Kubernetes for Data Engineers: Building Scalable, Reliable Data Pipelines
sucitw
1
200
カスタムしながら理解するGraphQL Connection
yanagii
1
1.2k
qmuntal/stateless のススメ
sgash708
0
120
Featured
See All Featured
Building Applications with DynamoDB
mza
90
6.1k
Making Projects Easy
brettharned
115
5.9k
How to Think Like a Performance Engineer
csswizardry
19
1.1k
A better future with KSS
kneath
238
17k
Designing the Hi-DPI Web
ddemaree
280
34k
RailsConf 2023
tenderlove
29
880
Agile that works and the tools we love
rasmusluckow
327
21k
[RailsConf 2023] Rails as a piece of cake
palkan
51
4.9k
YesSQL, Process and Tooling at Scale
rocio
167
14k
Teambox: Starting and Learning
jrom
132
8.7k
What's new in Ruby 2.0
geeforr
342
31k
Documentation Writing (for coders)
carmenintech
65
4.4k
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 • ӺใΛऔಘ͢Δ؆қͳΫϥΠΞϯτ • ࠓհͨ͠ςετΛஔ͍ͯ͋Γ·͢
͋Γ͕ͱ͏͍͟͝·ͨ͠