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

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Recently uploaded (20)

Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
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
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 

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