Your SlideShare is downloading. ×
0
AMIR BARYLKO                 TDD PATTERNS              FOR .NET DEVELOPERS                              PRAIRIE DEV CON   ...
WHO AM I?  • Architect  • Developer  • Mentor  • Great      cook  • The     one who’s entertaining you for the next hour!A...
WHY TDD?  • Test    first approach  • Quality      driven  • Easy    to refactor  • Regression        tests as byproduct  •...
SETUPAmir Barylko - TDD Patterns           MavenThought Inc.
TOOLS  •   Testing framework: NUnit, MbUnit, MSpec, MavenThought Testing  •   Mocking framework: Rhino Mocks, Moq, TypeMoc...
AUTO MOCKING  • Automatic         dependency creation for SUT  • Dictionary        of dependencies  • Faster     setup of ...
PATTERNSAmir Barylko - TDD Patterns              MavenThought Inc.
ONE FEATURE PER TEST  • Easy    to approach                 Given That                                        (arrange)  •...
STATE VERIFICATION  • Care     about the end state   var m = new Library...  • Does    not validate SUT     transitions   ...
BEHAVIOUR VERIFICATION  • Checking  the expected          var m = Mock<...>     behaviour happened  • Uses     mock object...
TEST WITH PARAMETERS                                   [Row(1)]  • Avoid   duplication and        [Row(2)]     repetition ...
DEPENDENCY INJECTION  • Remove  hardcoded              Initialize dependency     dependencies  • Introduces  dependency in...
DEPENDENCY LOOKUP  • Remove  hardcoded               Initialize service     dependencies                        locator  •...
DATABASE SETUP  • Base  class to setup the          Create Database     database  • The   test always works with a        ...
QUESTIONS?Amir Barylko - TDD Patterns                MavenThought Inc.
RESOURCES  • Contact       me: amir@barylko.com, @abarylko  • Download: http://www.orhtocoders.com/prairiedevcon  • Books:...
RESOURCES II  • NUnit: http://www.nunit.org  • Gallio     & MbUnit: http://www.gallio.org  • MavenThought Testing: http://...
prdc10-tdd-patterns
Upcoming SlideShare
Loading in...5
×

prdc10-tdd-patterns

419

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
419
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "prdc10-tdd-patterns"

  1. 1. AMIR BARYLKO TDD PATTERNS FOR .NET DEVELOPERS PRAIRIE DEV CON REGINA 2010Amir Barylko - TDD Patterns MavenThought Inc.
  2. 2. WHO AM I? • Architect • Developer • Mentor • Great cook • The one who’s entertaining you for the next hour!Amir Barylko - TDD Patterns MavenThought Inc.
  3. 3. WHY TDD? • Test first approach • Quality driven • Easy to refactor • Regression tests as byproduct • Increase developer’s confidenceAmir Barylko - TDD Patterns MavenThought Inc.
  4. 4. SETUPAmir Barylko - TDD Patterns MavenThought Inc.
  5. 5. TOOLS • Testing framework: NUnit, MbUnit, MSpec, MavenThought Testing • Mocking framework: Rhino Mocks, Moq, TypeMock • Test Automation: Scripts that can run the test from the developer computer. • CI server: Unit test should be run after each commit. • Reports and Notifications: The team should realize right away that the tests are broken.Amir Barylko - TDD Patterns MavenThought Inc.
  6. 6. AUTO MOCKING • Automatic dependency creation for SUT • Dictionary of dependencies • Faster setup of tests • Build your own: StructureMap • Or use MavenThought TestingAmir Barylko - TDD Patterns MavenThought Inc.
  7. 7. PATTERNSAmir Barylko - TDD Patterns MavenThought Inc.
  8. 8. ONE FEATURE PER TEST • Easy to approach Given That (arrange) • Easy to understand When I Run • Easy to maintain (act) • Enforce Given, When, Then Then it should ... (assert)Amir Barylko - TDD Patterns MavenThought Inc.
  9. 9. STATE VERIFICATION • Care about the end state var m = new Library... • Does not validate SUT transitions Run Test • Verifythe state agains the m.Count.Should(...) expected valueAmir Barylko - TDD Patterns MavenThought Inc.
  10. 10. BEHAVIOUR VERIFICATION • Checking the expected var m = Mock<...> behaviour happened • Uses mock objects m.Stub(...) • The behaviour is specified for each mock object Run Test • The expected methods m.AssertWasCalled(...) should be calledAmir Barylko - TDD Patterns MavenThought Inc.
  11. 11. TEST WITH PARAMETERS [Row(1)] • Avoid duplication and [Row(2)] repetition void Method(int arg) [Row(typeof(...))] • Generic Parameters void Method<T>(...) • Parameters Factories [Factory(...)] void Method(string arg) • Random strings void Method([Random]...) • Random numbers void Method([Random]..., [Factory]...)Amir Barylko - TDD Patterns MavenThought Inc.
  12. 12. DEPENDENCY INJECTION • Remove hardcoded Initialize dependency dependencies • Introduces dependency in Stub dependency with the constructor / setter mock • Easy to test and maintain Assert the mock is returned •S OLIDAmir Barylko - TDD Patterns MavenThought Inc.
  13. 13. DEPENDENCY LOOKUP • Remove hardcoded Initialize service dependencies locator • Introduces a factory or Stub to return a mock service locator • Easy to test and maintain Assert the mock is returned •S OLIDAmir Barylko - TDD Patterns MavenThought Inc.
  14. 14. DATABASE SETUP • Base class to setup the Create Database database • The test always works with a Populate clean database • Can be configured to Store populate data if needed Retrieve and AssertAmir Barylko - TDD Patterns MavenThought Inc.
  15. 15. QUESTIONS?Amir Barylko - TDD Patterns MavenThought Inc.
  16. 16. RESOURCES • Contact me: amir@barylko.com, @abarylko • Download: http://www.orhtocoders.com/prairiedevcon • Books: The rSpec book, xUnit Patterns.Amir Barylko - TDD Patterns MavenThought Inc.
  17. 17. RESOURCES II • NUnit: http://www.nunit.org • Gallio & MbUnit: http://www.gallio.org • MavenThought Testing: http://maventcommons.codeplex.com • Rhino Mocks: http://www.ayende.com • StructureMap: http://structuremap.sourcefore.com • TeamCity: http://www.jetbrains.comAmir Barylko - TDD Patterns MavenThought Inc.
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×