prdc10-tdd-patterns
Upcoming SlideShare
Loading in...5
×
 

prdc10-tdd-patterns

on

  • 578 views

 

Statistics

Views

Total Views
578
Views on SlideShare
578
Embed Views
0

Actions

Likes
0
Downloads
4
Comments
0

0 Embeds 0

No embeds

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

prdc10-tdd-patterns prdc10-tdd-patterns Presentation Transcript

  • AMIR BARYLKO TDD PATTERNS FOR .NET DEVELOPERS PRAIRIE DEV CON REGINA 2010Amir Barylko - TDD Patterns MavenThought Inc.
  • WHO AM I? • Architect • Developer • Mentor • Great cook • The one who’s entertaining you for the next hour!Amir Barylko - TDD Patterns MavenThought Inc.
  • WHY TDD? • Test first approach • Quality driven • Easy to refactor • Regression tests as byproduct • Increase developer’s confidenceAmir Barylko - TDD Patterns MavenThought Inc.
  • SETUPAmir Barylko - TDD Patterns MavenThought Inc.
  • 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.
  • 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.
  • PATTERNSAmir Barylko - TDD Patterns MavenThought Inc.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • QUESTIONS?Amir Barylko - TDD Patterns MavenThought Inc.
  • 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.
  • 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.