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

Evolutionary Software Design with TDD

Evolutionary Software Design with TDD

David Tanzer

June 29, 2016
Tweet

More Decks by David Tanzer

Other Decks in Programming

Transcript

  1. #@!*§&~#% I just wanted to change a single line of

    code… Now I have 20 red tests!
  2. I have lost count of the times where I have

    seen a developer mock out more than they need to because of excessive class coupling in their code. https://stephenhaunts.com/2013/03/07/all-your-mocks-are-evil/
  3. Sometimes the design is not clear at the start and

    evolves as you go along - this will force you to redo your test which will generate a big time lose. http://stackoverflow.com/questions/64333/disadvantages-of-test-driven-development
  4. Evil tests create a lock on how the code is

    implemented. http://www.makinggoodsoftware.com/2012/01/27/the-evil-unit-test/
  5. I think TDD is more like Othello: "A minute to

    learn. A lifetime to master." Jon Reid https://twitter.com/qcoding https://twitter.com/qcoding/status/433676850007506945 https://de.wikipedia.org/wiki/Othello_(Spiel)
  6. Today: • Test Driven Development • Components • Simple Design

    • SOLID • 2 Sides of an Interface • Outside-in vs Inside-out
  7. David Tanzer (@dtanzer) [email protected] I help my clients to: •

    Work together more effectively as a team • Improve their technical practices • Improve their software quality / design • Re-gain control of their legacy code http://davidtanzer.net
  8. If you can't build a monolith, what makes you think

    microservices are the answer? Simon Brown http://www.codingthearchitecture.com/2014/07/06/distributed_big_balls_of_mud.html
  9. Tests that… • Rely on a certain implementation • Cause

    duplication • Become red from time to time / for “no reason” • Are hard to read • Overlap • Test too much at once
  10. Design Principles • The Four Rules of Simple Design •

    S.O.L.I.D • Coupling / Cohesion • IoC / Dependency Injection • DDD
  11. Single Responsibility Principle “Every module or class should have responsibility

    over a single part of the functionality provided by the software, and that responsibility should be entirely encapsulated by the class.“ “A class should have only one reason to change.”
  12. Dependency Inversion Principle “High-level modules should not depend on low-level

    modules. Both should depend on abstractions. Abstractions should not depend on details. Details should depend on abstractions.“ “Your business logic should not depend on your infrastructure code.“
  13. Interface Segregation Principle “No client should be forced to depend

    on methods it does not use.“ “The consumer defines what it needs from an interface. Every consumer gets their own interface.“
  14. Test Doubles • Dummy Objekte that you pass around, but

    never really use. • Fake have an implementation, but are simpler than the „real“ object. • Stubs when invoked, always return canned answers. • Mocks give us a possibility to verify that they were used correctly during the test. http://martinfowler.com/articles/mocksArentStubs.html
  15. Architecture provides boundaries for TDD … e.g. Simon Brown (@simonbrown)

    https://twitter.com/simonbrown/status/746968018861821952 The best part was implementing the software TDD-style along the Component-Diagram, that felt very natural and made total sense. Kevin Wittek (@Kiview) https://twitter.com/Kiview/status/726350299150049280
  16. Have a design vision at any point in time •

    Make sure everyone is committed to it • Be wary if it’s still the same as one year ago
  17. Make sure your tests are small and simple So you

    won’t mind throwing them away if you have to
  18. TDD is like chess: you can learn the rule in

    a few minutes, but if you’re lucky, you’ll learn new things from it every day. J.B. Rainsberger https://twitter.com/jbrains https://twitter.com/jbrains/status/433659281544855552
  19. Thank You! [email protected] | @dtanzer I help my clients to:

    • Work together more effectively as a team • Improve their technical practices • Improve their software quality / design • Re-gain control of their legacy code http://davidtanzer.net
  20. Agile Acceptance Testing • Specify features only by defining their

    acceptance criteria • Write acceptance criteria in a way so that you can directly automate them as acceptance tests • Automate all testing (esp. acceptance tests)
  21. @Test public void returnsAddressWithValidStreetWhenUserIsValid() { User validUser = stubValidUser(…); Address

    address = addressService.addressFor(validUser); assertNotNull(address.getStreet()); }
  22. @Test public void returnsAddressWithValidStreetWhenUserIsValid() { User validUser = stubValidUser(…); Address

    address = addressService.addressFor(validUser); assumeNotNull(address); assertNotNull(address.getStreet()); }
  23. Architectural Topics • Security • Memory / Storage Performance •

    Throughput • Latency • Resilience Test them in an automated way!