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

MidwestDreamin16 - Mythbusters: Test Driven Dev...

MidwestDreamin16 - Mythbusters: Test Driven Development on Force.com projects

Testing is the key to successful long-term development and is a critical component of the development process. Salesforce's Best Practices strongly recommend that you use a test-driven development process, that is, test development that occurs at the same time as code development. But, how real is this in our projects? what are the long-term benefits? how to encourage developers to think test-first? is this feasible? Join us to discover myths and truths of TDD.

Avatar for Aldo Fernandez

Aldo Fernandez

July 22, 2016
Tweet

More Decks by Aldo Fernandez

Other Decks in Programming

Transcript

  1. #MWD16 Agenda • What is TDD? • The TDD process

    • An Apex TDD example • Benefits • Challenges
  2. #MWD16 What is TDD? (I) • It refers to a

    style of programming where three activities are tightly interwoven: • Coding • Testing (in the form of unit tests) • Design (in the form of refactoring)
  3. #MWD16 What is TDD? (II) “TDD is a software development

    approach where tests are written before the functional code” “TDD is a technique of using automated unit tests to drive the design of software and force decoupling of dependencies”
  4. #MWD16 Unit Testing: “Classic” vs “Mockist” styles • Mockist •

    Verify that a relatively small piece of code is doing what is intended to do • Narrow in scope • Easy to write and execute • Test useful for developers • No dependencies on external components • External components are mocked • Test internal consistency • Classic • Verify that different pieces of the system works correctly together • Covers whole business requirements/ features • Require more resource to complete • Test useful for business • Dependencies are required because the holistic approach • Test consistency between components
  5. #MWD16 Refactoring • “Refactoring is a controlled technique for improving

    the design of an existing code without changing its external behavior” —Martin Fowler • Improves non functional attributes • improve readability • reduce complexity • Key concept for code maintainability • Needed when “code smells”
  6. #MWD16 An Apex TDD example (I) • Aldo’s Algebra (don’t

    google, it’s just a specification example!) • Given 2 integer numbers (a,b) the sum operation will be a+b • If one of the numbers is null, treat it as zero • Examples • AA.sum(2,3) = 5 • AA.sum(2, null) = 2 • AA.sum(null, null) = 0
  7. #MWD16 Benefits • Forces a good architecture design • Reduce

    time of bug hunting • Write shorter and less complex code • Fewer System.debug() statements ;-) • Instant feedback on broken code • Code coverage on steroids! (go for 100%!) • Enforce KISS and Minium Viable Product concepts • Tests run faster • Mocking around SOQL and DML to avoid declarative changes failures (yes Admin, I’m watching at you!)
  8. #MWD16 Challenges • Learning curve • Cost of TDD vs

    Project Budget • ROI with TDD • Advanced concepts • Dependency Injection • Mocking • Cultural issues • Handling often business requirements changes
  9. #MWD16 Resources + Kudos • Test Driven Development Method in

    Software Development Process. Denis Duka, Lovre Hribar 2010 • Test Driven Development in Apex by Chris Aldridge (@caldrig3) • Unit Testing, Apex Enterprise Patterns and ApexMock, Andrew Fawcett (@andyinthecloud) • Writing true unit tests using dependency injection mocking apex, Alex Tennant (@adtennant) • ApexMocks: How Does It Work? Jesse Altman (@jessealtman) • Inversion of Control Containers and the Dependency Injection Pattern. Martin Fowler, 2004 • Demo Code repo: https://github.com/aldoforce/uysdug_tdd_demo
  10. #MWD16 Thank You! Mythbusters: Test Driven Development on Force.com projects

    Aldo Fernandez Technical Architect @aldoforce #MidwestDreamin16 #tdd #dependencyInjection #apex #testing