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
nekko cloudにおけるProxmox VE利用事例
irumaru
3
430
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
540
命名をリントする
chiroruxx
1
390
Асинхронность неизбежна: как мы проектировали сервис уведомлений
lamodatech
0
730
急成長期の品質とスピードを両立するフロントエンド技術基盤
soarteclab
0
930
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
PHPとAPI Platformで作る本格的なWeb APIアプリケーション(入門編) / phpcon 2024 Intro to API Platform
ttskch
0
170
開発者とQAの越境で自動テストが増える開発プロセスを実現する
92thunder
1
180
【re:Growth 2024】 Aurora DSQL をちゃんと話します!
maroon1st
0
770
Mermaid x AST x 生成AI = コードとドキュメントの完全同期への道
shibuyamizuho
0
160
Итераторы в Go 1.23: зачем они нужны, как использовать, и насколько они быстрые?
lamodatech
0
740
あれやってみてー駆動から成長を加速させる / areyattemite-driven
nashiusagi
1
200
Featured
See All Featured
Fashionably flexible responsive web design (full day workshop)
malarkey
405
66k
Visualization
eitanlees
146
15k
[RailsConf 2023] Rails as a piece of cake
palkan
53
5k
[RailsConf 2023 Opening Keynote] The Magic of Rails
eileencodes
28
9.1k
A designer walks into a library…
pauljervisheath
204
24k
A Tale of Four Properties
chriscoyier
157
23k
Reflections from 52 weeks, 52 projects
jeffersonlam
347
20k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
95
17k
The Cult of Friendly URLs
andyhume
78
6.1k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
10
810
VelocityConf: Rendering Performance Case Studies
addyosmani
326
24k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
29
2.3k
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 • ӺใΛऔಘ͢Δ؆қͳΫϥΠΞϯτ • ࠓհͨ͠ςετΛஔ͍ͯ͋Γ·͢
͋Γ͕ͱ͏͍͟͝·ͨ͠