Unit vs. Integration Tests
Softwerkskammer Meetup Munich
@codecentric
18.06.2015
David Völkel
@davidvoelkel
Unit vs. Integrated Tests
Isolated integratedvs.
Which do you prefer?
Isolated Integrated
1 2 3 4 5
Agenda
● Theory
● Unit vs. Integration Tests
● Test Pyramid
● How to achieve it
● Workshop
● What works well in our projects?
● Hardest challenges?
● How to address them?
● Another beer
Expensive Integrated Tests
Isolated Integrated
Creation &
Maintenance
cheap expensive
Feedback fast slow
Finding Errors easy difficult
Fragility minimal high
Significance for User medium high
4
n
+
m
n
*
m
Unit under test?
Isolated Integrated
Strengths Complex logic
(„combinatorial
explosion“),
conditionals, breadth
Integration, data
flow, depth
Test Pyramid
UI
Service
Unit
DegreeofIntegrationBy Mike Cohn
No: Test Pyramids!?!
By Mike Cohn
?
?
Unit
Orthogonal decomposition
By Mike Cohn
.
IntegratedTests
Isolated Tests &
Business Dimension
Acceptance Tests == UI-Tests?
Inspired through "the testing iceberg“ by Seb Rose / Matt Wynne
Acceptance Tests
Technical Tests
Business Domain
DegreeofIntegration .
Split up Acceptance Tests
Acceptance Tests
UI Domain Rules
Example Email Validation
N x integrated web tests
Input Output
„valid@email.de“ „Email OK“
„mail.without@tld“ „Email invalid“
„mail.without.at.de“ „Email invalid“
„@without-user.de“ „Email invalid“
…
valid
Example Email Validation
1 x integrated web tests
N x isolated tests
valid
Input Output
„valid@email.de“ „Email OK“
„mail.without@tld“ „Email invalid“
„mail.without.at.de“ „Email invalid“
„@without-user.de“ „Email invalid“
…
UI Test Pyramid
UI Test !=
End2End Tests
E2E
Compo
nent
Unit
DegreeofIntegration
(UI) End2End Tests
Fully integrated down to the backend
for
• backend interaction
• few logic (CRUD)
• simple workflows
• hardly testable legacy UI
E2E
Compo
nent
Unit
Back-
end
Gmail Example
E2E
Compo
nent
Unit
Minimal workflow
UI-Layer
component test
● testability required
● fat client
● SPA + REST
● server-side rendering?
E2E
Compo
nent
Unit
UI
Mock
Back
end
UI-Layer
for
• session status
• complex UI workflows
• workflows with few backend-
interaktion
E2E
Compo
nent
Unit
UI
Mock
Back
end
Gmail Example
E2E
Compo
nent
Unit
Mail editing
UI Unit Tests
for complex logic
value rendering
MVP: Presenter logic
Address example:
„D-80687, München, Elsenheimerstraße 55a“
„-, München, Elsenheimerstraße 55a“?
E2E
Compo
nent
Unit
UI
Resumee
UI
Service
Unit
Test Pyramid
• Integrated Tests: Integration &
Depth
• Isolierte Tests: Logic & Breadth
Orthogonal Decomposition
• Split up Acceptance Tests
• Business Rules
• UI
• E2E, UI Layer, UI Unit Tests
Workshop Agenda
● Round 1: current state in your project
● Successful solutions?
● Hardest challenges?
● Show & tell
● Round 2
● how can we improve?
● Show & tell
● Retrospective
Retrospective
License
Creative Commons Attribution-ShareAlike 3.0
https://creativecommons.org/licenses/by-sa/3.0/de/

Unit vs. Integration Tests