1 / 35

TDD Immersion

TDD Immersion. Jon Kruger Twitter: @ JonKruger Email: jon@jonkruger.com Blog: http://jonkruger.com/blog. Schedule. 1:30-2:00 Intro to TDD 2:05-2:35 Writing Testable Code 2:40-3:00 Mocking with Moq 3:05-3:55 Dependency Injection with StructureMap

Download Presentation

TDD Immersion

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. TDD Immersion Jon Kruger Twitter: @JonKruger Email: jon@jonkruger.com Blog: http://jonkruger.com/blog

  2. Schedule 1:30-2:00 Intro to TDD 2:05-2:35 Writing Testable Code 2:40-3:00 Mocking with Moq 3:05-3:55 Dependency Injection with StructureMap 4:00-4:30 Looking at sample code, wrap-up 4:30-5:30 Live coding action!!!

  3. So what’s the problem?

  4. Case Studies We don’t know what code is supposed to do “The Legacy Codebase”

  5. Case Studies We can’t prove that our code is working without someone manually verifying that it works “The Last Minute Change”

  6. Case Studies Bugs are a waste of time “The Infinite Loop of Bugs”

  7. Case Studies Low standards of quality “Throwing It Over the Wall”

  8. Case Studies Bugs can be really expensive to fix “Explosions and Blackouts”

  9. Case Studies Over time, code bases tend to become more chaotic and painful to work with “The Maintenance Nightmare”

  10. How can we solve these problems? • We need a way to ensure that our code is working • We need a way to ensure that our code will continue to work after someone changes it • We need a way to figure out what code is supposed to do • We need to make software development less stressful

  11. What is Test Driven Development? • A software development technique where you write automated unit tests before you write your implementation code • A technique for ensuring good quality and good design • Awesome!

  12. Example of a unit test [TestFixture] public class When_using_the_calculator { [Test] public void Should_add_two_numbers() { int result = new Calculator().Add(2, 3); result.ShouldEqual(5); } }

  13. Types of tests • Unit tests • Tests a small unit of functionality • Mock or “fake out” external dependencies (e.g. databases) • Run fast • Integration tests • Test the whole system working together • Can run slow • Can be brittle • Functional/Acceptance tests • End-to-end tests that test that a feature meets the needs of the business • Manual tests

  14. Unit Testing Frameworks • NUnit • MSTest • MBUnit • xUnit • MSpec

  15. The TDD Process • Write a test (or tests) for something. Since you haven’t written the implementation code yet, the tests should fail. • Write just enough code to get the test to pass. • Move on or refactor “Red – Green – Refactor”

  16. A Series of Translations

  17. Code!

  18. ?

  19. Benefits of TDD We know that our code is working!

  20. Benefits of TDD We know that our code will continue to work

  21. Benefits of TDD We didn’t write bugs

  22. Benefits of TDD We know when we are done

  23. Benefits of TDD We incrementally translated the requirements

  24. Behavior Driven Development • Testing the behavior of the system (not just data returned by a method) • Defining what it means for your system to work correctly (not just verifying that code works)

  25. Benefits of TDD Concentrate on the requirements/tests, then concentrate on implementation

  26. Benefits of TDD We only wrote as much code as we needed to make the tests pass

  27. Benefits of TDD Our tests helped us design our code

  28. Benefits of TDD We had to write testable code

  29. Benefits of TDD We couldn’t cheat and not write the tests

  30. Benefits of TDD Our tests are documentation of what our code does

  31. Benefits of TDD Our tests are documentation of what our code does • Someday someone other than you will have to understand your code • Someday you will wonder what your code was supposed to do • Living, breathing documentation!

  32. Benefits of TDD We can quickly regression test our code

  33. Benefits of TDD We can quickly regression test our code • Fewer bugs • Able to release more often • Less time spent doing manual testing • Prevent our app from becoming “legacy code”

  34. Benefits of TDD Peace of mind!

  35. ?

More Related