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
TDD in iOS
Search
Dominik Hauser
December 04, 2019
Programming
0
47
TDD in iOS
German presentation about TDD in iOS
Dominik Hauser
December 04, 2019
Tweet
Share
Other Decks in Programming
See All in Programming
🔨 小さなビルドシステムを作る
momeemt
4
680
そのAPI、誰のため? Androidライブラリ設計における利用者目線の実践テクニック
mkeeda
2
310
Ruby×iOSアプリ開発 ~共に歩んだエコシステムの物語~
temoki
0
320
Android 16 × Jetpack Composeで縦書きテキストエディタを作ろう / Vertical Text Editor with Compose on Android 16
cc4966
1
230
go test -json そして testing.T.Attr / Kyoto.go #63
utgwkk
3
300
@Environment(\.keyPath)那么好我不允许你们不知道! / atEnvironment keyPath is so good and you should know it!
lovee
0
120
GitHubとGitLabとAWS CodePipelineでCI/CDを組み比べてみた
satoshi256kbyte
4
240
基礎から学ぶ大画面対応(Learning Large-Screen Support from the Ground Up)
tomoya0x00
0
460
MCPとデザインシステムに立脚したデザインと実装の融合
yukukotani
4
1.4k
Swift Updates - Learn Languages 2025
koher
2
480
testingを眺める
matumoto
1
140
Performance for Conversion! 分散トレーシングでボトルネックを 特定せよ
inetand
0
160
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.5k
Mobile First: as difficult as doing things right
swwweet
224
9.9k
What’s in a name? Adding method to the madness
productmarketing
PRO
23
3.7k
Performance Is Good for Brains [We Love Speed 2024]
tammyeverts
12
1.1k
Bootstrapping a Software Product
garrettdimon
PRO
307
110k
Build your cross-platform service in a week with App Engine
jlugia
231
18k
Building a Modern Day E-commerce SEO Strategy
aleyda
43
7.6k
Designing for Performance
lara
610
69k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
34
6k
Imperfection Machines: The Place of Print at Facebook
scottboms
268
13k
Typedesign – Prime Four
hannesfritz
42
2.8k
We Have a Design System, Now What?
morganepeng
53
7.8k
Transcript
TDD und iOS Dominik Hauser, @dasdom
The quality and performance achieved could not have been done
without the use of unit testing. — Bill Bumgarner (bbum), über Core Data 1.0
Vorteile
Vorteile1 · Refaktorierbarkeit · Schnelles Feedback · Gedankenstütze · Doppelte
Buchführung · Regressionsschutz 1 Von (subjektiv) wichtig nach unwichtig
Planning/Feedback Loops Release Plan Code Iteration Plan Acceptance Test Stand
Up Meeting Pair Negotiation Unit Test Pair Programming Months Weeks Days One day Hours Minutes Seconds DonWells (CC BY-SA 3.0)
Wie? Red Green Refactor
Warum so wenig Tests?
"Was soll denn da kaputt gehen?"
if index-1 < userNames.count { nameLabel.text = userNames[index] } else
{ nameLabel.text = "Unknown" }
if index-1 < userNames.count { nameLabel.text = userNames[index] } else
{ nameLabel.text = "Unknown" }
class TableViewCell: UITableViewCell { let label = UILabel() override init(style:
UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) addSubview(label) } }
class TableViewCell: UITableViewCell { let label = UILabel() override init(style:
UITableViewCell.CellStyle, reuseIdentifier: String?) { super.init(style: style, reuseIdentifier: reuseIdentifier) addSubview(label) } }
"Was soll denn da kaputt gehen?" 1. That can’t happen.
2. That doesn’t happen on my machine. 3. That shouldn’t happen. 4. Why does that happen? 5. Oh, I see. 6. How did that ever work?2 2 Mike W. Cremer
"Machen wir nach dem Release."
RELEASE 1.0 TESTS RELEASE 1.1 Login Login Tests User User
Tests Logout Logout Tests Password reset Password Tests Blocking of users Blocking tests ... ...
RELEASE 1.0 RELEASE 1.1 TESTS Login Login Tests User User
Tests Logout Logout Tests Password reset Password Tests Blocking of users Blocking tests ... ...
RELEASE 1.0 RELEASE 1.1 RELEASE 1.1.1 Login User Logout Password
reset Blocking of users ... ...
Nach den Release ist vor den Release
"UI kann man nicht testen."
func test_viewHasLabel() { sut.loadViewIfNeeded() XCTAssertTrue(sut.label.isDescendant(of: sut.view)) }
func test_loadingView_registersCell() { // when sut.loadViewIfNeeded() // then let cell
= sut.tableView.dequeueReusableCell( withIdentifier: "Cell", for: IndexPath(row: 0, section: 0)) XCTAssertNotNil(cell) XCTAssertTrue(cell is Cell) }
func test_showNext_pushesViewController() { // given let navControllerMock = NavigationControllerMock( rootViewController:
sut) let user = User(name: "Foobar") // when sut.showNext(with: user) // then let detailController = navControllerMock.lastPushedVC as! DetailViewController XCTAssertEqual(detailController.user, user) }
"UI kann man nicht testen." Kann man
Tips & Tricks
Dependency Injection (Inversion of Control)
Zum Beispiel: Constructor Injection let defaultsStub = DefaultsStub(boolToReturn: false) let
user = User(defaults: defaultsStub)
Ausserdem · Constructor Injection · Setter Injection · Interface Injection
Abstraktion
Abstraktion Beispiel: Alerts protocol Alerter { func presentOKAlert(on: UIViewController, title:
String, message: String, okAction: ()->Void) }
View laden func test_foo() { // given ... // when
view loads sut.loadViewIfNeeded() // then ... }
viewWill/DidAppear func test_foo() { // given ... // when view
appears sut.beginAppearanceTransition(true, animated: false) sut.endAppearanceTransition() // then ... }
Modal presentation func test_presentationOfViewController() { // given let window =
UIWindow(frame: CGRect(x: 0, y: 0, width: 300, height: 300)) window.rootViewController = sut window.makeKeyAndVisible() // when sut.showNext() // then XCTAssertTrue(sut.presentedViewController is DetailViewController) }
Bestehender Code Wie anfangen?
Bug ➜ Test
Neues Feature ➜ Test
pragprog.com/book/jrlegios/ ios-unit-testing-by-example
Promolink http://leanpub.com/ tdd_ios_gimme_the_cod e/c/macdev
None
Promolink http://leanpub.com/ tdd_ios_gimme_the_cod e/c/macdev
Ende
Ende!
None