SlideShare a Scribd company logo
prdc10-tdd-patterns
AMIR BARYLKO
                 TDD PATTERNS
              FOR .NET DEVELOPERS
                              PRAIRIE DEV CON
                                REGINA 2010




Amir 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 confidence


Amir Barylko - TDD Patterns                MavenThought Inc.
SETUP




Amir 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 Testing


Amir Barylko - TDD Patterns                         MavenThought Inc.
PATTERNS




Amir 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 value




Amir 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 called

Amir 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    OLID


Amir 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    OLID


Amir 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 Assert


Amir 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.com

Amir Barylko - TDD Patterns                            MavenThought Inc.

More Related Content

PDF
Open source libraries and tools
PDF
PRDC-ror-trilogy-part1
PDF
CodeCamp 2012-mvc-vs-ror-2
PDF
every-day-automation
PDF
prdc10-Bdd-real-world
PDF
Jvm-bdd-quality-driven
PDF
Page objects pattern
PDF
Quality web-acceptance
Open source libraries and tools
PRDC-ror-trilogy-part1
CodeCamp 2012-mvc-vs-ror-2
every-day-automation
prdc10-Bdd-real-world
Jvm-bdd-quality-driven
Page objects pattern
Quality web-acceptance

What's hot (20)

PDF
Codemash-advanced-ioc-castle-windsor
PDF
mvcconf-bdd-quality-driven
PDF
decoupling-ea
PDF
Cpl12 continuous integration
PDF
CPL12-Agile-planning
PDF
YEG-UG-Capybara
PDF
Capybara1
PDF
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
KEY
Irb Tips and Tricks
PDF
Agile planning
PDF
Agile requirements
KEY
Social dev camp_2011
KEY
Android java fx-jme@jug-lugano
KEY
Becoming a more productive Rails Developer
KEY
WebGL Camp 4 - A3 3D Engine
KEY
WTF TDD?
KEY
Project Tools in Web Development
PDF
JRuby in The Enterprise
PDF
Automated UI test on mobile - with Cucumber/Calabash
PPTX
Philly CocoaHeads 20160414 - Building Your App SDK With Swift
Codemash-advanced-ioc-castle-windsor
mvcconf-bdd-quality-driven
decoupling-ea
Cpl12 continuous integration
CPL12-Agile-planning
YEG-UG-Capybara
Capybara1
Aki Salmi - Refactoring legacy code: a true story @ I T.A.K.E. Unconference 2...
Irb Tips and Tricks
Agile planning
Agile requirements
Social dev camp_2011
Android java fx-jme@jug-lugano
Becoming a more productive Rails Developer
WebGL Camp 4 - A3 3D Engine
WTF TDD?
Project Tools in Web Development
JRuby in The Enterprise
Automated UI test on mobile - with Cucumber/Calabash
Philly CocoaHeads 20160414 - Building Your App SDK With Swift
Ad

Similar to prdc10-tdd-patterns (20)

PDF
Tdd patterns1
PDF
why-tdd
PDF
PRDC11-tdd-common-mistakes
PPTX
TDD Training
PDF
Tddbdd workshop
PDF
2012 regina TC - 103 quality driven
PDF
Real developers-dont-need-unit-tests
PDF
Real developers-dont-need-unit-tests
PDF
Real developers-dont-need-unit-tests
PDF
Journey's diary developing a framework using tdd
PPTX
Test Driven Development:Unit Testing, Dependency Injection, Mocking
PDF
Design for Testability
PDF
An Introduction to Test Driven Development
PDF
Test and Behaviour Driven Development (TDD/BDD)
PDF
Developing an Ember Test Strategy - EmberConf 2019
PPT
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская
KEY
TDD refresher
KEY
Driving application development through behavior driven development
PPT
Test Driven Development - Overview and Adoption
PPTX
Test Driven Development - a Practitioner’s Perspective
Tdd patterns1
why-tdd
PRDC11-tdd-common-mistakes
TDD Training
Tddbdd workshop
2012 regina TC - 103 quality driven
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-tests
Real developers-dont-need-unit-tests
Journey's diary developing a framework using tdd
Test Driven Development:Unit Testing, Dependency Injection, Mocking
Design for Testability
An Introduction to Test Driven Development
Test and Behaviour Driven Development (TDD/BDD)
Developing an Ember Test Strategy - EmberConf 2019
Solit 2012, TDD и отдельные аспекты тестирования в Java, Антонина Шафранская
TDD refresher
Driving application development through behavior driven development
Test Driven Development - Overview and Adoption
Test Driven Development - a Practitioner’s Perspective
Ad

More from Amir Barylko (20)

PDF
Functional converter project
PDF
Elm: delightful web development
PDF
Dot Net Core
PDF
No estimates
PDF
User stories deep dive
PDF
Coderetreat hosting training
PDF
There's no charge for (functional) awesomeness
PDF
What's new in c# 6
PDF
Productive teams
PDF
Who killed object oriented design?
PDF
From coach to owner - What I learned from the other side
PDF
Communication is the Key to Teamwork and productivity
PDF
Acceptance Test Driven Development
PDF
Refactoring
PDF
Agile teams and responsibilities
PDF
Refactoring
PDF
Beutiful javascript with coffeescript
PDF
Sass & bootstrap
PDF
Rich UI with Knockout.js &amp; Coffeescript
PDF
Agile requirements
Functional converter project
Elm: delightful web development
Dot Net Core
No estimates
User stories deep dive
Coderetreat hosting training
There's no charge for (functional) awesomeness
What's new in c# 6
Productive teams
Who killed object oriented design?
From coach to owner - What I learned from the other side
Communication is the Key to Teamwork and productivity
Acceptance Test Driven Development
Refactoring
Agile teams and responsibilities
Refactoring
Beutiful javascript with coffeescript
Sass & bootstrap
Rich UI with Knockout.js &amp; Coffeescript
Agile requirements

Recently uploaded (20)

PDF
cuic standard and advanced reporting.pdf
PDF
Empathic Computing: Creating Shared Understanding
PPTX
A Presentation on Artificial Intelligence
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
Approach and Philosophy of On baking technology
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
cuic standard and advanced reporting.pdf
Empathic Computing: Creating Shared Understanding
A Presentation on Artificial Intelligence
Programs and apps: productivity, graphics, security and other tools
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Approach and Philosophy of On baking technology
Assigned Numbers - 2025 - Bluetooth® Document
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
Per capita expenditure prediction using model stacking based on satellite ima...
NewMind AI Weekly Chronicles - August'25-Week II
Mobile App Security Testing_ A Comprehensive Guide.pdf
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf

prdc10-tdd-patterns

  • 2. AMIR BARYLKO TDD PATTERNS FOR .NET DEVELOPERS PRAIRIE DEV CON REGINA 2010 Amir Barylko - TDD Patterns MavenThought Inc.
  • 3. WHO AM I? • Architect • Developer • Mentor • Great cook • The one who’s entertaining you for the next hour! Amir Barylko - TDD Patterns MavenThought Inc.
  • 4. WHY TDD? • Test first approach • Quality driven • Easy to refactor • Regression tests as byproduct • Increase developer’s confidence Amir Barylko - TDD Patterns MavenThought Inc.
  • 5. SETUP Amir Barylko - TDD Patterns MavenThought Inc.
  • 6. 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.
  • 7. AUTO MOCKING • Automatic dependency creation for SUT • Dictionary of dependencies • Faster setup of tests • Build your own: StructureMap • Or use MavenThought Testing Amir Barylko - TDD Patterns MavenThought Inc.
  • 8. PATTERNS Amir Barylko - TDD Patterns MavenThought Inc.
  • 9. 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.
  • 10. 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 value Amir Barylko - TDD Patterns MavenThought Inc.
  • 11. 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 called Amir Barylko - TDD Patterns MavenThought Inc.
  • 12. 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.
  • 13. 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 OLID Amir Barylko - TDD Patterns MavenThought Inc.
  • 14. 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 OLID Amir Barylko - TDD Patterns MavenThought Inc.
  • 15. 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 Assert Amir Barylko - TDD Patterns MavenThought Inc.
  • 16. QUESTIONS? Amir Barylko - TDD Patterns MavenThought Inc.
  • 17. 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.
  • 18. 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.com Amir Barylko - TDD Patterns MavenThought Inc.