SlideShare a Scribd company logo
1 of 24
Introduction to
Test Driven Development
           And
         Mocking
        @saeed_shargi
The Problem
Time taken to fix bugs
1000



750



500



250



  0
        Design   Implementation   QA   Post-Release
Solution


   Testing

   Test Driven Development
Testing



Design   Implementation   Test
TDD



Design   Test   Implementation
TDD



Design   Test     Implementation   Test
TDD
          Design




Test                    Test




       Implementation
TDD
          Design




Test                    Test




       Implementation
What is TDD?
 Write a test before writing a code.
 Specification not validation
 Think through requirements or design
  before write code.
 Programming technique
 Ron Jefferies -> write clean code
What is TDD?
What is TDD?
What is TDD?



TDD = Refactoring + TFD
Two Level of TDD

1)   Acceptance TDD (ATDD)



2)   Developer TDD
ATDD and TDD Together
Development Style


1)   KISS
               Writing only the code
               necessary to pass test
2)   YAGNI
Benefits
1)   Suit unit test provides that components
     working.
2)   Clear code
3)   Forces critical analysis and design
4)   Better design , loosely coupled , easily
     maintainable
5)   Reduced debugging time
Tools
   Cpputest
   csUnit (.Net)
   Cunit
   Dunit (Delphi)
   DBUnit
   JUnit
   NUnit
   PHPUnit
   xUnit.net
Mocking
 Simple classes dose not have
  dependencies.
 In Action classes maybe have external
  dependencies like connect to database
  , connect to web services.
 Good Test should be isolated.
 Integration test.
 Test should be fast.
Mocking

   Two way to isolated :

    1) Use Interface
    2) Mocking framework
Example of using Interface
   Interfaces to isolated database and
    web services :

public interface IEmailSource
{
  IEnumerable<string> GetEmailAddresses();
}

public interface IEmailDataStore
{
  void SaveEmailAddresses(IEnumerable<string> emailAddresses);

}
Example of using Interface
      Mock classes :
    public class MockEmailSource : IEmailSource
    {
      public IEnumerable<string> EmailAddressesToReturn { get; set; }
      public IEnumerable<string> GetEmailAddresses()
      {
        return EmailAddressesToReturn;
      }
    }

    public class MockEmailDataStore : IEmailDataStore
    {
      public IEnumerable<string> SavedEmailAddresses { get; set; }
      public void SaveEmailAddresses(IEnumerable<string> emailAddresses)
      {
        SavedEmailAddresses = emailAddresses;
      }
    }
Mocking Frameworks
 Nmock
 Moq
 Rhino Mocks
 TypeMock
 EasyMock.Net
Introduction to TDD and Mocking

More Related Content

What's hot

Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Zohirul Alam Tiemoon
 
Tdd in php a brief example
Tdd in php   a brief exampleTdd in php   a brief example
Tdd in php a brief example
Jeremy Kendall
 
Quickly and Effectively Testing Legacy c++ Code with Approval Tests mu cpp
Quickly and Effectively Testing Legacy c++ Code with Approval Tests   mu cppQuickly and Effectively Testing Legacy c++ Code with Approval Tests   mu cpp
Quickly and Effectively Testing Legacy c++ Code with Approval Tests mu cpp
Clare Macrae
 

What's hot (20)

TDD with Visual Studio 2010
TDD with Visual Studio 2010TDD with Visual Studio 2010
TDD with Visual Studio 2010
 
TDD - Agile
TDD - Agile TDD - Agile
TDD - Agile
 
Working With Legacy Code
Working With Legacy CodeWorking With Legacy Code
Working With Legacy Code
 
Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010Test Driven Development (TDD) Preso 360|Flex 2010
Test Driven Development (TDD) Preso 360|Flex 2010
 
Unit testing legacy code
Unit testing legacy codeUnit testing legacy code
Unit testing legacy code
 
Working Effectively With Legacy Code
Working Effectively With Legacy CodeWorking Effectively With Legacy Code
Working Effectively With Legacy Code
 
Refactoring Legacy Code
Refactoring Legacy CodeRefactoring Legacy Code
Refactoring Legacy Code
 
Clean code - Getting your R&D on board
Clean code - Getting your R&D on boardClean code - Getting your R&D on board
Clean code - Getting your R&D on board
 
How we tested our code "Google way"
How we tested our code "Google way"How we tested our code "Google way"
How we tested our code "Google way"
 
Testing the untestable
Testing the untestableTesting the untestable
Testing the untestable
 
TDD Flow: The Mantra in Action
TDD Flow: The Mantra in ActionTDD Flow: The Mantra in Action
TDD Flow: The Mantra in Action
 
XPDays Ukraine: Legacy
XPDays Ukraine: LegacyXPDays Ukraine: Legacy
XPDays Ukraine: Legacy
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
Overview on TDD (Test Driven Development) & ATDD (Acceptance Test Driven Deve...
 
Tdd in php a brief example
Tdd in php   a brief exampleTdd in php   a brief example
Tdd in php a brief example
 
A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD) A Not-So-Serious Introduction to Test Driven Development (TDD)
A Not-So-Serious Introduction to Test Driven Development (TDD)
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
An Introduction to Test Driven Development
An Introduction to Test Driven Development An Introduction to Test Driven Development
An Introduction to Test Driven Development
 
Quickly and Effectively Testing Legacy c++ Code with Approval Tests mu cpp
Quickly and Effectively Testing Legacy c++ Code with Approval Tests   mu cppQuickly and Effectively Testing Legacy c++ Code with Approval Tests   mu cpp
Quickly and Effectively Testing Legacy c++ Code with Approval Tests mu cpp
 
Top 20 cucumber interview questions for sdet
Top 20 cucumber interview questions for sdetTop 20 cucumber interview questions for sdet
Top 20 cucumber interview questions for sdet
 

Viewers also liked

Test Driven Development (C#)
Test Driven Development (C#)Test Driven Development (C#)
Test Driven Development (C#)
Alan Dean
 
Unit 18 compare and contrast presentation
Unit 18 compare and contrast presentationUnit 18 compare and contrast presentation
Unit 18 compare and contrast presentation
Lisa
 

Viewers also liked (20)

Tdd - introduction
Tdd - introductionTdd - introduction
Tdd - introduction
 
Service Virtualization - Next Gen Testing Conference Singapore 2013
Service Virtualization - Next Gen Testing Conference Singapore 2013Service Virtualization - Next Gen Testing Conference Singapore 2013
Service Virtualization - Next Gen Testing Conference Singapore 2013
 
TDD and BDD in Java 8 - what's in it for me?
TDD and BDD in Java 8 - what's in it for me?TDD and BDD in Java 8 - what's in it for me?
TDD and BDD in Java 8 - what's in it for me?
 
Is Groovy better for testing than Java?
Is Groovy better for testing than Java?Is Groovy better for testing than Java?
Is Groovy better for testing than Java?
 
Rapport diagnostic numérique 2012
Rapport diagnostic numérique 2012Rapport diagnostic numérique 2012
Rapport diagnostic numérique 2012
 
Noble Purpose: How to Win the Hearts and Minds of Your Employees
Noble Purpose: How to Win the Hearts and Minds of Your EmployeesNoble Purpose: How to Win the Hearts and Minds of Your Employees
Noble Purpose: How to Win the Hearts and Minds of Your Employees
 
Introduction to TDD
Introduction to TDDIntroduction to TDD
Introduction to TDD
 
TDD Introduction with Kata FizzBuzz
TDD Introduction with Kata FizzBuzzTDD Introduction with Kata FizzBuzz
TDD Introduction with Kata FizzBuzz
 
Lisa
LisaLisa
Lisa
 
Stub Testing and Driver Testing
Stub Testing and Driver TestingStub Testing and Driver Testing
Stub Testing and Driver Testing
 
Test Driven Development (C#)
Test Driven Development (C#)Test Driven Development (C#)
Test Driven Development (C#)
 
BDD Anti-patterns
BDD Anti-patternsBDD Anti-patterns
BDD Anti-patterns
 
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose presoTest Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
Test Driven Development (TDD) with FlexUnit 4 - 360|Flex San Jose preso
 
La virtualisation
La virtualisationLa virtualisation
La virtualisation
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD And Refactoring
TDD And RefactoringTDD And Refactoring
TDD And Refactoring
 
TDD Overview
TDD OverviewTDD Overview
TDD Overview
 
La virtualisation
La virtualisationLa virtualisation
La virtualisation
 
The WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpecThe WHY behind TDD/BDD and the HOW with RSpec
The WHY behind TDD/BDD and the HOW with RSpec
 
Unit 18 compare and contrast presentation
Unit 18 compare and contrast presentationUnit 18 compare and contrast presentation
Unit 18 compare and contrast presentation
 

Similar to Introduction to TDD and Mocking

Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
bhochhi
 
Mercury Testdirector8.0 Admin Slides
Mercury Testdirector8.0 Admin SlidesMercury Testdirector8.0 Admin Slides
Mercury Testdirector8.0 Admin Slides
telab
 

Similar to Introduction to TDD and Mocking (20)

Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
Journey's diary developing a framework using tdd
Journey's diary   developing a framework using tddJourney's diary   developing a framework using tdd
Journey's diary developing a framework using tdd
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Tdd is not about testing (OOP)
Tdd is not about testing (OOP)Tdd is not about testing (OOP)
Tdd is not about testing (OOP)
 
Mercury Testdirector8.0 Admin Slides
Mercury Testdirector8.0 Admin SlidesMercury Testdirector8.0 Admin Slides
Mercury Testdirector8.0 Admin Slides
 
TDD refresher
TDD refresherTDD refresher
TDD refresher
 
Desenvolvendo um Framework com TDD - Um Diário de Bordo - Agile Trends 2014
Desenvolvendo um Framework com TDD - Um Diário de Bordo - Agile Trends 2014Desenvolvendo um Framework com TDD - Um Diário de Bordo - Agile Trends 2014
Desenvolvendo um Framework com TDD - Um Diário de Bordo - Agile Trends 2014
 
Tdd on play framework
Tdd on play frameworkTdd on play framework
Tdd on play framework
 
Coding Naked
Coding NakedCoding Naked
Coding Naked
 
TDD- Test Driven Development
TDD- Test Driven DevelopmentTDD- Test Driven Development
TDD- Test Driven Development
 
Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)Tdd is not about testing (C++ version)
Tdd is not about testing (C++ version)
 
Stopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under TestStopping the Rot - Putting Legacy C++ Under Test
Stopping the Rot - Putting Legacy C++ Under Test
 
The Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs PublicThe Magic Of Application Lifecycle Management In Vs Public
The Magic Of Application Lifecycle Management In Vs Public
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and Adoption
 
Tdd blog
Tdd blogTdd blog
Tdd blog
 
Introduction to Test Driven Development
Introduction to Test Driven DevelopmentIntroduction to Test Driven Development
Introduction to Test Driven Development
 
Binary Studio Academy: .NET Code Testing
Binary Studio Academy: .NET Code TestingBinary Studio Academy: .NET Code Testing
Binary Studio Academy: .NET Code Testing
 
NET Code Testing
NET Code TestingNET Code Testing
NET Code Testing
 
TDD in functional testing with WebDriver
TDD in functional testing with WebDriverTDD in functional testing with WebDriver
TDD in functional testing with WebDriver
 
BDD and Test Automation in Evalutionary Product Suite
BDD and Test Automation in Evalutionary Product SuiteBDD and Test Automation in Evalutionary Product Suite
BDD and Test Automation in Evalutionary Product Suite
 

Recently uploaded

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
giselly40
 

Recently uploaded (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 

Introduction to TDD and Mocking

  • 1. Introduction to Test Driven Development And Mocking @saeed_shargi
  • 3. Time taken to fix bugs 1000 750 500 250 0 Design Implementation QA Post-Release
  • 4. Solution  Testing  Test Driven Development
  • 5. Testing Design Implementation Test
  • 6. TDD Design Test Implementation
  • 7. TDD Design Test Implementation Test
  • 8. TDD Design Test Test Implementation
  • 9. TDD Design Test Test Implementation
  • 10. What is TDD?  Write a test before writing a code.  Specification not validation  Think through requirements or design before write code.  Programming technique  Ron Jefferies -> write clean code
  • 13. What is TDD? TDD = Refactoring + TFD
  • 14. Two Level of TDD 1) Acceptance TDD (ATDD) 2) Developer TDD
  • 15. ATDD and TDD Together
  • 16. Development Style 1) KISS Writing only the code necessary to pass test 2) YAGNI
  • 17. Benefits 1) Suit unit test provides that components working. 2) Clear code 3) Forces critical analysis and design 4) Better design , loosely coupled , easily maintainable 5) Reduced debugging time
  • 18. Tools  Cpputest  csUnit (.Net)  Cunit  Dunit (Delphi)  DBUnit  JUnit  NUnit  PHPUnit  xUnit.net
  • 19. Mocking  Simple classes dose not have dependencies.  In Action classes maybe have external dependencies like connect to database , connect to web services.  Good Test should be isolated.  Integration test.  Test should be fast.
  • 20. Mocking  Two way to isolated : 1) Use Interface 2) Mocking framework
  • 21. Example of using Interface  Interfaces to isolated database and web services : public interface IEmailSource { IEnumerable<string> GetEmailAddresses(); } public interface IEmailDataStore { void SaveEmailAddresses(IEnumerable<string> emailAddresses); }
  • 22. Example of using Interface  Mock classes : public class MockEmailSource : IEmailSource { public IEnumerable<string> EmailAddressesToReturn { get; set; } public IEnumerable<string> GetEmailAddresses() { return EmailAddressesToReturn; } } public class MockEmailDataStore : IEmailDataStore { public IEnumerable<string> SavedEmailAddresses { get; set; } public void SaveEmailAddresses(IEnumerable<string> emailAddresses) { SavedEmailAddresses = emailAddresses; } }
  • 23. Mocking Frameworks  Nmock  Moq  Rhino Mocks  TypeMock  EasyMock.Net