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

Beyond Unit Testing - The Real Value of TDD - Client Talk

Beyond Unit Testing - The Real Value of TDD - Client Talk

Twenty years after the public introduction of Test-Driven Development (TDD), in Kent Beck's Extreme Programming Explained, it remains a commonly misunderstood and underutilized practice. While there are many who espouse the benefits of TDD, misconceptions about the practice and its perceived learning curve serve to dampen its impact on the software industry.

This talk introduces the misconceptions about TDD, as being just another way to write unit tests. It disputes this belief by refocusing on the many benefits of the practice. The talk will detail the resulting sustainable, high-quality test suites that are a product of TDD. Additionally, it will describe the less visible benefits like software design feedback, and improvements to development structure and developer workflow; all of which are possible through the continued practice of TDD.

If you are a software engineer or a technical leader wanting to learn more about TDD, looking for the motivation to give the practice a try, or are looking for ways to encourage your team(s) to learn the practice, this talk is for you.

Anthony Sciamanna

June 08, 2021
Tweet

More Decks by Anthony Sciamanna

Other Decks in Programming

Transcript

  1. Beyond Unit Testing
    The Real Value of Test-Driven Development
    Anthony Sciamanna
    Senior Consultant
    Industrial Logic
    June 8, 2021

    View full-size slide

  2. TDD Refresher
    Image by Industrial Logic Senior Consultant - Tim Ottinger
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  3. @asciamanna
    anthonysciamanna.com
    TDD Refresher

    View full-size slide

  4. TDD Refresher
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  5. TD Refresher
    Let’s go back in time!
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  6. TD Refresher
    A Very Brief History of TDD
    1994
    Kent Beck releases the first version of the SUnit framework
    for Smalltalk
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  7. TD Refresher
    A Very Brief History of TDD
    1994
    1995
    Kent demos TDD to Ward Cunningham at OOPSLA Austin in
    October. Details of the C3 Project start being publicized
    Kent Beck releases the first version of the SUnit framework
    for Smalltalk
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  8. TD Refresher
    A Very Brief History of TDD
    1994
    1995
    1997
    Kent demos TDD to Ward Cunningham at OOPSLA Austin in
    October. Details of the C3 Project start being publicized
    Kent Beck releases the first version of the SUnit framework
    for Smalltalk
    On a flight from Zurich to Atlanta (OOPSLA ‘97) Erich
    Gamma and Kent Beck create JUnit for Java
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  9. TD Refresher
    A Very Brief History of TDD
    1994
    1995
    1997
    1999
    Kent demos TDD to Ward Cunningham at OOPSLA Austin in
    October. Details of the C3 Project start being publicized
    Kent Beck releases the first version of the SUnit framework
    for Smalltalk
    On a flight from Zurich to Atlanta (OOPSLA ‘97) Erich
    Gamma and Kent Beck create JUnit for Java
    Kent releases Extreme Programming Explained
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  10. TDD Is a Testing Practice
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  11. @asciamanna
    anthonysciamanna.com
    I don’t care if people write tests first or last.
    As long as they get written.
    - Anonymous Tech Lead

    View full-size slide

  12. @asciamanna
    anthonysciamanna.com
    Ignores Design and Workflow Benefits of TDD

    View full-size slide

  13. Benefits of TDD
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  14. Benefits of TDD
    @asciamanna
    anthonysciamanna.com
    Externally Visible Artifacts
    Test Suite

    View full-size slide

  15. Benefits of TDD
    @asciamanna
    anthonysciamanna.com
    Externally Visible Artifacts
    Test Suite

    View full-size slide

  16. Benefits of TDD
    Externally Visible Artifacts
    @asciamanna
    anthonysciamanna.com
    Software
    Design
    Test Suite

    View full-size slide

  17. Benefits of TDD
    Externally Visible Artifacts
    @asciamanna
    anthonysciamanna.com
    Developer
    Workflow
    Software
    Design
    Test Suite

    View full-size slide

  18. Benefits of TDD
    Externally Visible Artifacts
    @asciamanna
    anthonysciamanna.com
    Developer
    Workflow
    Software
    Design
    Test Suite

    View full-size slide

  19. TDD Triple
    Balance
    anthonysciamanna.com
    Maker Making
    Made
    @asciamanna

    View full-size slide

  20. Benefits of TDD
    Externally Visible Artifacts
    anthonysciamanna.com
    Developer
    Workflow
    Software
    Design
    Test Suite
    @asciamanna

    View full-size slide

  21. Test Suite Benefits
    Why we prefer TDD-style tests over Test After Tests

    View full-size slide

  22. Test Suite
    Quality
    Production
    Code
    Quality
    Test suite quality influences production
    code quality and vice-versa
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  23. You Can’t Write Good Tests for Bad Code
    • Wrapping untestable code in unit tests
    results in brittle, low-quality tests
    • Test-first practices enable writing high
    quality production code and high-quality
    tests
    Markus Spiske for Tech Daily
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  24. The TDD Quality Cycle
    Test Suite Production Code
    2. Code under test must be
    testable (loosely coupled)
    Refactoring
    Refactoring
    3. Enables tests to be
    small, precise, fast,
    isolated and independent
    Virtuous
    Cycle
    1. We start in the test
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  25. Microtest
    A short, simple, fast, isolated*,
    test that probes the behavior
    of a single class
    *Isolated does not mean we have to mock every dependency
    anthonysciamanna.com @asciamanna

    View full-size slide

  26. Microtests Don’t
    Access a network
    Access a database
    Access the filesystem
    Depend on other tests
    Require a complex environment to run in
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  27. S
    O
    S
    anthonysciamanna.com @asciamanna

    View full-size slide

  28. Small
    O
    S
    anthonysciamanna.com @asciamanna

    View full-size slide

  29. Small
    Obvious
    S
    anthonysciamanna.com @asciamanna

    View full-size slide

  30. Small
    Obvious
    Simple
    anthonysciamanna.com
    @asciamanna

    View full-size slide

  31. Small
    ~12 LOC or less per test
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  32. Obvious
    anthonysciamanna.com
    @asciamanna

    View full-size slide

  33. Arrange
    Act
    Assert
    Arrange – Act – Assert
    Or
    Given - When - Then
    anthonysciamanna.com @asciamanna

    View full-size slide

  34. Standardize common test constructs
    Create the object under test in Setup
    Standard name result to be asserted
    Standard name for object under test
    anthonysciamanna.com
    @asciamanna

    View full-size slide

  35. Simple
    Avoid branching
    and flow control
    logic in tests
    anthonysciamanna.com @asciamanna

    View full-size slide

  36. How To Stop Hating Your Test Suite
    Logic in tests confuses the story of what’s being tested. Test-
    scoped logic is hard to read and errors are easy to miss.
    - Justin Searls, Co-founder Test Double
    anthonysciamanna.com @asciamanna

    View full-size slide

  37. How To Stop Hating Your Test Suite
    Test code is untested code!
    - Justin Searls, Co-founder Test Double
    anthonysciamanna.com @asciamanna

    View full-size slide

  38. anthonysciamanna.com @asciamanna
    Test After Test First
    Manual testing often takes precedence
    Unit testing at end tends to be skipped to
    hit deadlines
    All code is tested as it is created or modified
    Feels like busy work if code is manually tested
    and considered “done”
    The test is the path to changing the system
    Code is not influenced by tests to be testable Code is influenced by the tests to be testable
    Tests don’t serve as feedback loops Tests are continuous feedback loops, supports
    refactoring and software design
    Tests don’t get refactored – created at end Tests are continuously refactored
    Tests are less comprehensive when added at
    end
    Tests are more comprehensive when added
    with each code change
    Coverage as a build gate often required
    (commonly 70% coverage)
    Coverage metrics unnecessary
    VS.

    View full-size slide

  39. Software Design Benefits
    Tests guiding quality software design

    View full-size slide

  40. TDD Disclaimer
    TDD influences design quality
    But it’s not a magic wand!
    anthonysciamanna.com @asciamanna

    View full-size slide

  41. TDD Disclaimer
    TDD influences design quality
    High Cohesion Loose Coupling
    Small Classes Small Methods
    anthonysciamanna.com @asciamanna

    View full-size slide

  42. TDD Disclaimer
    TDD provides a mechanism
    for learning software design
    High Cohesion Loose Coupling
    Small Classes Small Methods
    anthonysciamanna.com @asciamanna

    View full-size slide

  43. Practitioners still need to understand
    the concepts of software design
    TDD Disclaimer
    High Cohesion Loose Coupling
    Code Smells Design Patterns
    SOLID
    Refactoring
    Encapsulation
    GRASP
    Connascence
    anthonysciamanna.com @asciamanna

    View full-size slide

  44. Test-Driven Development
    Refactoring
    Legacy Code
    Techniques
    Microtesting
    / Test Suite
    Design
    Code Smells Design
    Patterns
    Cohesion &
    Coupling
    SOLID
    Continuous
    Integration
    Continuous
    Delivery
    Evolutionary
    Design
    Collaborative
    Development
    Iterative
    Development
    anthonysciamanna.com @asciamanna

    View full-size slide

  45. Microtests are litmus tests
    for software design quality
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  46. Examples
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  47. Too Much Test Setup
    Too Many Dependencies Too Many Arguments
    Arguments are Too Complex Code Under Test Doing Too Much
    anthonysciamanna.com @asciamanna

    View full-size slide

  48. Multiple ‘Act’ Steps
    Temporal Coupling Exists
    Complicated API
    Client needs to know too
    much about object under test
    Too Many Steps to Invoke
    Method Under Test
    anthonysciamanna.com @asciamanna

    View full-size slide

  49. Too Many Asserts
    Returning too complex of a type
    Code under test doing too much
    anthonysciamanna.com @asciamanna

    View full-size slide

  50. Too Many Test Cases
    Too much branching logic
    Code under test is
    doing too much
    anthonysciamanna.com @asciamanna

    View full-size slide

  51. Client-First Design / Outside-In
    TDD enables software design from a client’s perspective
    Leads to better designed interfaces between objects
    anthonysciamanna.com @asciamanna

    View full-size slide

  52. Refactoring into design yields a better design than Big Design Up Front
    Requirements Design Code Test
    Waterfall Mindset
    Requirements Test Code
    Design
    (Refactor)
    (Test-Driven) Agile Mindset
    Slide courtesy of Mike Rieser (@MichaelRieser)
    anthonysciamanna.com @asciamanna

    View full-size slide

  53. Developer Workflow Benefits
    Short, fast feedback cycles improve productivity

    View full-size slide

  54. Nearly instantaneous
    feedback loops
    anthonysciamanna.com @asciamanna

    View full-size slide

  55. Fast Feedback Loops
    key to developer
    productivity & high
    performing teams
    anthonysciamanna.com @asciamanna

    View full-size slide

  56. anthonysciamanna.com @asciamanna

    View full-size slide

  57. Resilient to Interruptions
    anthonysciamanna.com @asciamanna

    View full-size slide

  58. TDD-created Microtests are save states for system functionality
    anthonysciamanna.com @asciamanna

    View full-size slide

  59. anthonysciamanna.com @asciamanna

    View full-size slide

  60. BIG PROBLEM
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  61. BIG PROBLEM
    @asciamanna
    anthonysciamanna.com
    Great software is created by GREAT TEAMS not heroic, rockstar, 10X
    developers working in isolation

    View full-size slide

  62. BIG PROBLEM
    @asciamanna
    anthonysciamanna.com
    Software development is a communication game
    Communication is the professional developer’s first order of
    business. Perhaps you thought that ‘getting it working’ was the
    first order of business for a professional developer. I hope by now,
    however, this book has disabused you of that idea.
    - Robert Martin, Clean Code

    View full-size slide

  63. System is always in a working state
    anthonysciamanna.com @asciamanna

    View full-size slide

  64. Tiny Validations
    anthonysciamanna.com @asciamanna

    View full-size slide

  65. https://www.geepawhill.org/2018/04/14/tdd-the-lump-of-coding-fallacy/
    anthonysciamanna.com @asciamanna
    GeePaw Hill – TDD & the Lump of Coding Fallacy

    View full-size slide

  66. https://www.geepawhill.org/2018/04/14/tdd-the-lump-of-coding-fallacy/
    anthonysciamanna.com @asciamanna
    GeePaw Hill – TDD & the Lump of Coding Fallacy

    View full-size slide

  67. https://www.geepawhill.org/2018/04/14/tdd-the-lump-of-coding-fallacy/
    anthonysciamanna.com @asciamanna
    GeePaw Hill – TDD & the Lump of Coding Fallacy

    View full-size slide

  68. https://www.geepawhill.org/2018/04/14/tdd-the-lump-of-coding-fallacy/
    anthonysciamanna.com @asciamanna
    GeePaw Hill – TDD & the Lump of Coding Fallacy

    View full-size slide

  69. Mental Benefits of TDD
    One of the hardest things to communicate about Test-Driven
    Development is the mental state it puts you in…On the original C3
    project…progress was steady and unhurried; because it was unhurried it
    seemed slow, but looking back on how much we got done, it was clear
    that despite the unhurried feeling progress was really fast.


    anthonysciamanna.com @asciamanna

    View full-size slide

  70. Mental Benefits of TDD
    Concrete and visible progress on small incremental goals
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  71. Mental Benefits of TDD
    @asciamanna
    anthonysciamanna.com
    Achieving Profluence

    View full-size slide

  72. Mental Benefits of TDD
    Little or no time spent in the
    debugger or on repetitive,
    time consuming manual
    checks
    anthonysciamanna.com @asciamanna

    View full-size slide

  73. Learning TDD will help improve software design, developer
    workflow, increases developer happiness, and it’s a lot of fun!
    https://geepawhill.org
    https://github.com/testdouble/contributing-tests/wiki
    Test Double – Contributing Tests Wiki
    Industrial Logic
    eLearning
    https://www.industriallogic.com/elearning/
    anthonysciamanna.com @asciamanna

    View full-size slide

  74. http://bit.ly/beyond-unit-testing-2021
    @asciamanna
    anthonysciamanna.com

    View full-size slide

  75. Attributes
    • Pygmy Marmoset - https://www.flickr.com/photos/gopak/39889008421
    • SOS - https://www.flickr.com/photos/itupictures/16654290295
    • Darts - https://www.flickr.com/photos/mike-burns/374198933
    • Quote - Nick Youngson CC BY-SA 3.0
    • Magician - Photo by Pierrick VAN-TROOST on Unsplash
    • Litmus test - https://commons.wikimedia.org/wiki/File:Blue_and_red_litmus_paper.JPG
    • Self-operating napkin - https://upload.wikimedia.org/wikipedia/commons/8/88/Self-
    operating_napkin_%28Rube_Goldberg_cartoon_with_caption%29.jpg
    • Glass Cockpit - https://upload.wikimedia.org/wikipedia/commons/9/9f/C-5M_Cockpit.jpg
    • Public Domain, https://commons.wikimedia.org/w/index.php?curid=2466026
    • Stack of Papers - https://upload.wikimedia.org/wikipedia/commons/b/b6/FileStack_retouched.jpg
    • El Diablo - https://en.wikipedia.org/wiki/Fire_Ball#/media/File:El_Diablo_Roller_Coaster.jpg
    • Creative Commons license: https://creativecommons.org/licenses/by/2.0/

    View full-size slide