Agenda
- Architectural patterns
- What about MVC?
- Shared principles (between architectural patterns)
- Test-Driven Development
- The approach - Outside-In development
- Demo (problem and code example)
What about MVC?
MVC is the half of the user menta model
soure
Slide 8
Slide 8 text
What about MVC?
MVC is the half of the user menta model
DCI is the other half
soure
Slide 9
Slide 9 text
What about MVC?
Trygve
Reenskaug
James Coplien
Slide 10
Slide 10 text
Shared principles
Slide 11
Slide 11 text
Shared principles
1. Independent of Frameworks.
2. Testable.
3. Independent of UI.
4. Independent of Database.
5. Independent of any external agency.
Slide 12
Slide 12 text
Shared principles
Slide 13
Slide 13 text
Shared principles
Ports, are
contracts on the
boundaries.
Adapters, are
implementations
of the available
ports to connect
the app to the
outside world.
Slide 14
Slide 14 text
Shared principles
The outside world is anything that is not really important
to solve the problem:
Database, UI/HTTP/Graphql (Delivery mechanism), frameworks
(Mobile, Web, … etc)
Slide 15
Slide 15 text
Shared principles
Slide 16
Slide 16 text
TDD
Slide 17
Slide 17 text
TDD traditional Cycle TDD Pyramid
Slide 18
Slide 18 text
About unit tests
A test is not a unit test if:
- It talks to a database
- It communicates across the network
- It touches the file system
- You have to do things to your environment to run it (eg,
change config files, comment line)
- Tests that do this are integration tests.
Slide 19
Slide 19 text
About unit tests
For isolation usually people talk about mocks, in reality
mocks are one of the test doubles that help to to write unit
tests:
- Mock
- Fake
- Spy
- Stub
- Dummy
Slide 20
Slide 20 text
The approach
Slide 21
Slide 21 text
Outside-In Development with Double loop TDD
Slide 22
Slide 22 text
Outside-In Development with Double loop TDD
Source
Slide 23
Slide 23 text
Outside-In Development with Double loop TDD
1. Write failing acceptance test for the application service
behavior.
2. Write the application service code.
3. See the test fail.
4. Write failing microtest for domain model (core) code and see the
test fail.
5. Write/design domain model code that makes the microtest pass.
6. At some point the same microtest exercise is needed to write
contract tests for ports/interfaces adapters implementations .
7. Repeat 4 to 6 until the acceptance test pass.
Slide 24
Slide 24 text
Outside-In Development with Double loop TDD
- Acceptance tests exercise domain model and infrastructure
based on the acceptance criteria
- Microtests exercise the domain model.
- Contract tests exercise infrastructure ports & adapters
implementations.
Slide 25
Slide 25 text
Outside-In Development with Double loop TDD
Slide 26
Slide 26 text
The problem
Slide 27
Slide 27 text
The problem
Shopping cart rules:
- The cart can not be orderable if it is empty
- Item lines quantities are aggregated
Slide 28
Slide 28 text
The problem
Shopping cart examples (acceptance criteria):
- A new cart adds fried chicken, the output should say 1
fried chicken
- A cart with fried chicken, it adds another fried chicken,
the output should say there’s 2 fried chicken