Unit vs. Integration Tests

25
Unit vs. Integration Tests Softwerkskammer Meetup Munich @codecentric 18.06.2015 David Völkel @davidvoelkel

Transcript of Unit vs. Integration Tests

Unit vs. Integration Tests

Softwerkskammer Meetup Munich

@codecentric

18.06.2015

David Völkel

@davidvoelkel

Unit vs. Integrated Tests

Isolated

integrated vs.

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

http://www.jeasyui.com/tutorial/app/crud.php

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

De

gre

e o

f In

tegra

tio

n

By Mike Cohn

No: Test Pyramids!?!

By Mike Cohn

?

?

Unit

Orthogonal decomposition

By Mike Cohn

. Inte

gra

ted

Tests

Isolated Tests &

Business Dimension

Acceptance Tests == UI-Tests?

Inspired through "the testing iceberg“ by Seb Rose / Matt Wynne

Acceptance Tests

Technical Tests

Business Domain

De

gre

e o

f In

teg

ratio

n .

Split up Acceptance Tests

Acceptance Tests

UI Domain Rules

Example Email Validation

N x integrated web tests

Input Output

[email protected]“ „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

[email protected]“ „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

De

gre

e o

f In

tegra

tio

n

(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

15

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/