Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Test-Driven Architecture

Test-Driven Architecture

Mohamed Cherif Bouchelaghem

February 04, 2023
Tweet

More Decks by Mohamed Cherif Bouchelaghem

Other Decks in Programming

Transcript

  1. Agenda - Architectural patterns - What about MVC? - Shared

    principles (between architectural patterns) - Test-Driven Development - The approach - Outside-In development - Demo (problem and code example)
  2. What about MVC? MVC is the half of the user

    menta model DCI is the other half soure
  3. Shared principles 1. Independent of Frameworks. 2. Testable. 3. Independent

    of UI. 4. Independent of Database. 5. Independent of any external agency.
  4. Shared principles Ports, are contracts on the boundaries. Adapters, are

    implementations of the available ports to connect the app to the outside world.
  5. 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)
  6. TDD

  7. 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.
  8. 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
  9. 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.
  10. 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.
  11. The problem Shopping cart rules: - The cart can not

    be orderable if it is empty - Item lines quantities are aggregated
  12. 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
  13. References - https://blog.cleancoder.com/uncle-bob/2012/08/13/the-clean-architectu re.html - https://jeffreypalermo.com/2008/07/the-onion-architecture-part-1/ - https://web.archive.org/web/20180822100852/http://alistair.cockburn.u s/Hexagonal+architecture -

    https://jmgarridopaz.github.io/content/hexagonalarchitecture.html - https://www.destroyallsoftware.com/screencasts/catalog/functional-cor e-imperative-shell - https://coding-is-like-cooking.info/2013/04/outside-in-development-wi th-double-loop-tdd/ - https://netflixtechblog.com/ready-for-changes-with-hexagonal-architec ture-b315ec967749 -