SlideShare a Scribd company logo
Test-Driven Development
Code testing, mocking, dependency injection, benefits and recent criticism
Mayank Srivastava
Manager and Evangelist
www.MayankSrivastava.com
http://www.mpspartners.com/blogs
@MayankSri
Know your audience
• Didn’t quite use TDD but used Unit / integration tests.
• Used TDD on a project.
What we will cover today:
• TDD concept
• Unit test
• Dependency Injection
• Resource Mocking
• Integration tests
• Best Practices
• Recent Criticism
• Open forum (Opinions, comments, experiences, questions)
Waterfall - Initial Development methodology
Agile
• Iterative & incremental
• Small manageable units of work
• Collaboration between self-organizing, cross-functional teams
• Develop small pieces and put it before the user first.
• Adaptive, evolutionary development & delivery
• Built to last – rapid and flexible response to change
Test-driven development relies on the repetition of a very
short development cycle:
First the developer writes an automated test case that defines a
desired improvement or new function,
then produces the minimum amount of code to pass that test,
And finally refactors the new code to acceptable standards.
Red – Green - Refactor
In short…
Absolutely!
start with testing what you haven’t written yet.
You need TDD
If you
• Are going to maintain code base developed by other developers.
• Work with developers who do not accept their code has bugs.
• Are going to make changes to someone else’s code and then
someone else is not available before deployment.
• Spend good amount of time trying to identify what par of the code
base is causing the problem.
TDD - key benefits
• Test is written against requirements.
• Provides built-in regression testing.
• Testable code, by design, follows SOLID principals.
• Ensure quality from the start.
• Puts an end to recurring bugs from Waterfall.
Unit Test
A test written to validate “One (logical) Unit” of work.
Unit
• Isolated from other code
• Isolated from other developers
Test
• Targetable
• Repeatable
• Predictable
Decoupling the Unit with Dependencies
You unit of work is dependent on external resources like:
• A persistence medium
• Logging system
• A caching mechanism
• An external service like a web or windows based service.
Decoupling dependencies
Dependency Injection
Using IoC resolver to inject dependency
IoC container example (Using Ninject)
Instantiating dependent with dependencies
Using providers
Finally
Resolving Dependency at run time
Mocking dependencies
Why Mocking?
Options:
• Custom rolled mock implementation of dependency
• Frameworks like Moq, RhinoMocks, Nsubstitute etc…
Mocking with Moq
Integration test
• Any test that crosses the boundary of a Unit is Integration test.
• A full spike - end to end feature test.
Best practice / lesson learnt
• Naming test cases (Readable & Verbose)
• Exhaustive test cases – pass, fail, corner cases and conditions
• Test only the code you wrote.
• Must target all business logic / features.
• Limit mocking maintenance burden.
• Don’t cheat… ever (once or twice is enough to bring the suite down)
Recent criticism - TDD is dead. Long live Testing.
• Unit testing is very shallow and it does not has a cross layer reach.
• Too much focus on execution time of the regression test suite.
• TDD tends to Mocks heavy architecture, everything stubbed out creates refactoring difficult.
• Red-green-refactor loop – less optional and more of a mandate. Some developers do not really enjoy that
development.
• TDD nudges towards over testing cost, testing code is still code that needs maintenance.
• Reduced QA people – the person who created cannot be the person who will test to break. But in reality, it
eliminated the testers who only run pre written test scripts.
• Cost Vs life of the system (ignore rare cases)
6 Google hangout sessions on YouTube - http://www.youtube.com/watch?v=z9quxZsLcfo
Benefits
• Business requirement are living running test cases not document that
can be missed.
• Have I broken anything while making a change? – Self testing
regression suite.
• Is this code base healthy? The code base is handed over to different
Open forum
Experiences
Opinions
Questions
Audience-Driven Development exercise.
Thank you.

More Related Content

What's hot

Using Crowdsourced Testing to Turbocharge your Development Team
Using Crowdsourced Testing to Turbocharge your Development TeamUsing Crowdsourced Testing to Turbocharge your Development Team
Using Crowdsourced Testing to Turbocharge your Development Team
Rainforest QA
 
Continous testing for grails
Continous testing for grailsContinous testing for grails
Continous testing for grails
winkler1
 
QA Process Overview for Firefox OS 2014
QA Process Overview for Firefox OS 2014QA Process Overview for Firefox OS 2014
QA Process Overview for Firefox OS 2014
Anthony Chung
 
Benefits from AATs
Benefits from AATsBenefits from AATs
Benefits from AATs
Wyn B. Van Devanter
 
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...Steve Lange
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
Shawn Jones
 
Why Automated Testing Matters To DevOps
Why Automated Testing Matters To DevOpsWhy Automated Testing Matters To DevOps
Why Automated Testing Matters To DevOps
dpaulmerrill
 
Unit Testing in Swift
Unit Testing in SwiftUnit Testing in Swift
Unit Testing in Swift
GlobalLogic Ukraine
 
Unit Testing talk
Unit Testing talkUnit Testing talk
Unit Testing talk
Sergei Kukharev
 
Agile Engineering Sparker GLASScon 2015
Agile Engineering Sparker GLASScon 2015Agile Engineering Sparker GLASScon 2015
Agile Engineering Sparker GLASScon 2015
Stephen Ritchie
 
Android tdd
Android tddAndroid tdd
Android tdd
Nhan Cao
 
Automated testing overview
Automated testing overviewAutomated testing overview
Automated testing overview
Alex Pop
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
Md. Enamul Haque Chowdhury
 
Avoiding test hell
Avoiding test hellAvoiding test hell
Avoiding test hell
Yun Ki Lee
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
Lars Thorup
 
Software Testing, Everyone's responsibility
Software Testing, Everyone's responsibilitySoftware Testing, Everyone's responsibility
Software Testing, Everyone's responsibility
Kurt Bliefernich
 
Intro to devops - Begin with End in Mind
Intro to devops - Begin with End in MindIntro to devops - Begin with End in Mind
Intro to devops - Begin with End in Mind
Laavanya Kathiresen
 
Put "fast" back in "fast feedback"
Put "fast" back in "fast feedback"Put "fast" back in "fast feedback"
Put "fast" back in "fast feedback"
Lars Thorup
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
ZendCon
 

What's hot (20)

Using Crowdsourced Testing to Turbocharge your Development Team
Using Crowdsourced Testing to Turbocharge your Development TeamUsing Crowdsourced Testing to Turbocharge your Development Team
Using Crowdsourced Testing to Turbocharge your Development Team
 
Continous testing for grails
Continous testing for grailsContinous testing for grails
Continous testing for grails
 
QA Process Overview for Firefox OS 2014
QA Process Overview for Firefox OS 2014QA Process Overview for Firefox OS 2014
QA Process Overview for Firefox OS 2014
 
Benefits from AATs
Benefits from AATsBenefits from AATs
Benefits from AATs
 
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
PHX - Session #2 Test Driven Development: Improving .NET Application Performa...
 
A Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven DevelopmentA Brief Introduction to Test-Driven Development
A Brief Introduction to Test-Driven Development
 
Why Automated Testing Matters To DevOps
Why Automated Testing Matters To DevOpsWhy Automated Testing Matters To DevOps
Why Automated Testing Matters To DevOps
 
Unit Testing in Swift
Unit Testing in SwiftUnit Testing in Swift
Unit Testing in Swift
 
Unit Testing talk
Unit Testing talkUnit Testing talk
Unit Testing talk
 
Agile Engineering Sparker GLASScon 2015
Agile Engineering Sparker GLASScon 2015Agile Engineering Sparker GLASScon 2015
Agile Engineering Sparker GLASScon 2015
 
Android tdd
Android tddAndroid tdd
Android tdd
 
Automated testing overview
Automated testing overviewAutomated testing overview
Automated testing overview
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Avoiding test hell
Avoiding test hellAvoiding test hell
Avoiding test hell
 
Introduction to Automated Testing
Introduction to Automated TestingIntroduction to Automated Testing
Introduction to Automated Testing
 
Software Testing, Everyone's responsibility
Software Testing, Everyone's responsibilitySoftware Testing, Everyone's responsibility
Software Testing, Everyone's responsibility
 
Automation and Technical Debt
Automation and Technical DebtAutomation and Technical Debt
Automation and Technical Debt
 
Intro to devops - Begin with End in Mind
Intro to devops - Begin with End in MindIntro to devops - Begin with End in Mind
Intro to devops - Begin with End in Mind
 
Put "fast" back in "fast feedback"
Put "fast" back in "fast feedback"Put "fast" back in "fast feedback"
Put "fast" back in "fast feedback"
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 

Viewers also liked

CNUG - Effective Data Visualization
CNUG - Effective Data VisualizationCNUG - Effective Data Visualization
CNUG - Effective Data Visualization
Mayank Srivastava
 
Targeting Mobile Platform with MVC 4.0
Targeting Mobile Platform with MVC 4.0Targeting Mobile Platform with MVC 4.0
Targeting Mobile Platform with MVC 4.0Mayank Srivastava
 
CNUG ASP.NET MVC 4 – New Features
CNUG ASP.NET MVC 4 – New FeaturesCNUG ASP.NET MVC 4 – New Features
CNUG ASP.NET MVC 4 – New FeaturesMayank Srivastava
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
Mayank Srivastava
 
CNUG - Getting started on IoT Devices & Solutions using Windows 10 & Microsof...
CNUG - Getting started on IoT Devices & Solutions using Windows 10 & Microsof...CNUG - Getting started on IoT Devices & Solutions using Windows 10 & Microsof...
CNUG - Getting started on IoT Devices & Solutions using Windows 10 & Microsof...
Mayank Srivastava
 

Viewers also liked (7)

Introduction to HTML5
Introduction to HTML5Introduction to HTML5
Introduction to HTML5
 
CNUG - Effective Data Visualization
CNUG - Effective Data VisualizationCNUG - Effective Data Visualization
CNUG - Effective Data Visualization
 
Why do you need REST
Why do you need RESTWhy do you need REST
Why do you need REST
 
Targeting Mobile Platform with MVC 4.0
Targeting Mobile Platform with MVC 4.0Targeting Mobile Platform with MVC 4.0
Targeting Mobile Platform with MVC 4.0
 
CNUG ASP.NET MVC 4 – New Features
CNUG ASP.NET MVC 4 – New FeaturesCNUG ASP.NET MVC 4 – New Features
CNUG ASP.NET MVC 4 – New Features
 
Introduction to ASP.NET MVC
Introduction to ASP.NET MVCIntroduction to ASP.NET MVC
Introduction to ASP.NET MVC
 
CNUG - Getting started on IoT Devices & Solutions using Windows 10 & Microsof...
CNUG - Getting started on IoT Devices & Solutions using Windows 10 & Microsof...CNUG - Getting started on IoT Devices & Solutions using Windows 10 & Microsof...
CNUG - Getting started on IoT Devices & Solutions using Windows 10 & Microsof...
 

Similar to CNUG TDD June 2014

Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.
Malinda Kapuruge
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
Peter Kofler
 
Test Driven Development – What Works And What Doesn’t
Test Driven Development – What Works And What Doesn’t Test Driven Development – What Works And What Doesn’t
Test Driven Development – What Works And What Doesn’t
Synerzip
 
Test Driven Development using QUnit
Test Driven Development using QUnitTest Driven Development using QUnit
Test Driven Development using QUnit
satejsahu
 
Test planning and software's engineering
Test planning and software's engineeringTest planning and software's engineering
Test planning and software's engineering
MansiganeshJawale
 
Topic production code
Topic production codeTopic production code
Topic production code
Kavi Kumar
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolatorMaslowB
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testingBestBrains
 
Agile testing
Agile testingAgile testing
Agile testing
Raj Indugula
 
Test Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s PerspectiveTest Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s Perspective
Malinda Kapuruge
 
Test Driven Development & CI/CD
Test Driven Development & CI/CDTest Driven Development & CI/CD
Test Driven Development & CI/CD
Shanmuga S Muthu
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
nikhil sreeni
 
No Devops Without Continuous Testing
No Devops Without Continuous TestingNo Devops Without Continuous Testing
No Devops Without Continuous Testing
Parasoft
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Codecamp Romania
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
Ganesh Kondal
 
Enter the mind of an Agile Developer
Enter the mind of an Agile DeveloperEnter the mind of an Agile Developer
Enter the mind of an Agile Developer
BSGAfrica
 
Kku2011
Kku2011Kku2011
Introduction to Unit Tests and TDD
Introduction to Unit Tests and TDDIntroduction to Unit Tests and TDD
Introduction to Unit Tests and TDD
Betclic Everest Group Tech Team
 
Agile Testing - What is it?
Agile Testing - What is it?Agile Testing - What is it?
Agile Testing - What is it?
Intelliware Development Inc.
 

Similar to CNUG TDD June 2014 (20)

Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.Understanding TDD - theory, practice, techniques and tips.
Understanding TDD - theory, practice, techniques and tips.
 
TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)TDD and Related Techniques for Non Developers (2012)
TDD and Related Techniques for Non Developers (2012)
 
Test Driven Development – What Works And What Doesn’t
Test Driven Development – What Works And What Doesn’t Test Driven Development – What Works And What Doesn’t
Test Driven Development – What Works And What Doesn’t
 
Test Driven Development using QUnit
Test Driven Development using QUnitTest Driven Development using QUnit
Test Driven Development using QUnit
 
Test planning and software's engineering
Test planning and software's engineeringTest planning and software's engineering
Test planning and software's engineering
 
Topic production code
Topic production codeTopic production code
Topic production code
 
Type mock isolator
Type mock isolatorType mock isolator
Type mock isolator
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Introduction to-automated-testing
Introduction to-automated-testingIntroduction to-automated-testing
Introduction to-automated-testing
 
Agile testing
Agile testingAgile testing
Agile testing
 
Test Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s PerspectiveTest Driven Development - a Practitioner’s Perspective
Test Driven Development - a Practitioner’s Perspective
 
Test Driven Development & CI/CD
Test Driven Development & CI/CDTest Driven Development & CI/CD
Test Driven Development & CI/CD
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
No Devops Without Continuous Testing
No Devops Without Continuous TestingNo Devops Without Continuous Testing
No Devops Without Continuous Testing
 
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
Iasi code camp 20 april 2013 marian chicu - database unit tests in the sql se...
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
Enter the mind of an Agile Developer
Enter the mind of an Agile DeveloperEnter the mind of an Agile Developer
Enter the mind of an Agile Developer
 
Kku2011
Kku2011Kku2011
Kku2011
 
Introduction to Unit Tests and TDD
Introduction to Unit Tests and TDDIntroduction to Unit Tests and TDD
Introduction to Unit Tests and TDD
 
Agile Testing - What is it?
Agile Testing - What is it?Agile Testing - What is it?
Agile Testing - What is it?
 

Recently uploaded

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
Paco van Beckhoven
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
abdulrafaychaudhry
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
Matt Welsh
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
Georgi Kodinov
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
Globus
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Shahin Sheidaei
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
Globus
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
Adele Miller
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
WSO2
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
Fermin Galan
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
Globus
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
Google
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Globus
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
wottaspaceseo
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
Srikant77
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
Donna Lenk
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
Globus
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
Ortus Solutions, Corp
 

Recently uploaded (20)

Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024Cracking the code review at SpringIO 2024
Cracking the code review at SpringIO 2024
 
Lecture 1 Introduction to games development
Lecture 1 Introduction to games developmentLecture 1 Introduction to games development
Lecture 1 Introduction to games development
 
Large Language Models and the End of Programming
Large Language Models and the End of ProgrammingLarge Language Models and the End of Programming
Large Language Models and the End of Programming
 
2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx2024 RoOUG Security model for the cloud.pptx
2024 RoOUG Security model for the cloud.pptx
 
Enhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdfEnhancing Research Orchestration Capabilities at ORNL.pdf
Enhancing Research Orchestration Capabilities at ORNL.pdf
 
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
Gamify Your Mind; The Secret Sauce to Delivering Success, Continuously Improv...
 
GlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote sessionGlobusWorld 2024 Opening Keynote session
GlobusWorld 2024 Opening Keynote session
 
May Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdfMay Marketo Masterclass, London MUG May 22 2024.pdf
May Marketo Masterclass, London MUG May 22 2024.pdf
 
Accelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with PlatformlessAccelerate Enterprise Software Engineering with Platformless
Accelerate Enterprise Software Engineering with Platformless
 
Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024Globus Compute wth IRI Workflows - GlobusWorld 2024
Globus Compute wth IRI Workflows - GlobusWorld 2024
 
Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604Orion Context Broker introduction 20240604
Orion Context Broker introduction 20240604
 
First Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User EndpointsFirst Steps with Globus Compute Multi-User Endpoints
First Steps with Globus Compute Multi-User Endpoints
 
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing SuiteAI Pilot Review: The World’s First Virtual Assistant Marketing Suite
AI Pilot Review: The World’s First Virtual Assistant Marketing Suite
 
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
Exploring Innovations in Data Repository Solutions - Insights from the U.S. G...
 
How Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptxHow Recreation Management Software Can Streamline Your Operations.pptx
How Recreation Management Software Can Streamline Your Operations.pptx
 
RISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent EnterpriseRISE with SAP and Journey to the Intelligent Enterprise
RISE with SAP and Journey to the Intelligent Enterprise
 
Prosigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology SolutionsProsigns: Transforming Business with Tailored Technology Solutions
Prosigns: Transforming Business with Tailored Technology Solutions
 
Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"Navigating the Metaverse: A Journey into Virtual Evolution"
Navigating the Metaverse: A Journey into Virtual Evolution"
 
How to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good PracticesHow to Position Your Globus Data Portal for Success Ten Good Practices
How to Position Your Globus Data Portal for Success Ten Good Practices
 
BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024BoxLang: Review our Visionary Licenses of 2024
BoxLang: Review our Visionary Licenses of 2024
 

CNUG TDD June 2014

  • 1. Test-Driven Development Code testing, mocking, dependency injection, benefits and recent criticism Mayank Srivastava Manager and Evangelist www.MayankSrivastava.com http://www.mpspartners.com/blogs @MayankSri
  • 2. Know your audience • Didn’t quite use TDD but used Unit / integration tests. • Used TDD on a project.
  • 3. What we will cover today: • TDD concept • Unit test • Dependency Injection • Resource Mocking • Integration tests • Best Practices • Recent Criticism • Open forum (Opinions, comments, experiences, questions)
  • 4. Waterfall - Initial Development methodology
  • 5. Agile • Iterative & incremental • Small manageable units of work • Collaboration between self-organizing, cross-functional teams • Develop small pieces and put it before the user first. • Adaptive, evolutionary development & delivery • Built to last – rapid and flexible response to change
  • 6.
  • 7. Test-driven development relies on the repetition of a very short development cycle: First the developer writes an automated test case that defines a desired improvement or new function, then produces the minimum amount of code to pass that test, And finally refactors the new code to acceptable standards.
  • 8. Red – Green - Refactor
  • 9. In short… Absolutely! start with testing what you haven’t written yet.
  • 10. You need TDD If you • Are going to maintain code base developed by other developers. • Work with developers who do not accept their code has bugs. • Are going to make changes to someone else’s code and then someone else is not available before deployment. • Spend good amount of time trying to identify what par of the code base is causing the problem.
  • 11. TDD - key benefits • Test is written against requirements. • Provides built-in regression testing. • Testable code, by design, follows SOLID principals. • Ensure quality from the start. • Puts an end to recurring bugs from Waterfall.
  • 12. Unit Test A test written to validate “One (logical) Unit” of work. Unit • Isolated from other code • Isolated from other developers Test • Targetable • Repeatable • Predictable
  • 13. Decoupling the Unit with Dependencies You unit of work is dependent on external resources like: • A persistence medium • Logging system • A caching mechanism • An external service like a web or windows based service.
  • 16. Using IoC resolver to inject dependency
  • 17. IoC container example (Using Ninject)
  • 23. Options: • Custom rolled mock implementation of dependency • Frameworks like Moq, RhinoMocks, Nsubstitute etc…
  • 25. Integration test • Any test that crosses the boundary of a Unit is Integration test. • A full spike - end to end feature test.
  • 26. Best practice / lesson learnt • Naming test cases (Readable & Verbose) • Exhaustive test cases – pass, fail, corner cases and conditions • Test only the code you wrote. • Must target all business logic / features. • Limit mocking maintenance burden. • Don’t cheat… ever (once or twice is enough to bring the suite down)
  • 27. Recent criticism - TDD is dead. Long live Testing. • Unit testing is very shallow and it does not has a cross layer reach. • Too much focus on execution time of the regression test suite. • TDD tends to Mocks heavy architecture, everything stubbed out creates refactoring difficult. • Red-green-refactor loop – less optional and more of a mandate. Some developers do not really enjoy that development. • TDD nudges towards over testing cost, testing code is still code that needs maintenance. • Reduced QA people – the person who created cannot be the person who will test to break. But in reality, it eliminated the testers who only run pre written test scripts. • Cost Vs life of the system (ignore rare cases) 6 Google hangout sessions on YouTube - http://www.youtube.com/watch?v=z9quxZsLcfo
  • 28. Benefits • Business requirement are living running test cases not document that can be missed. • Have I broken anything while making a change? – Self testing regression suite. • Is this code base healthy? The code base is handed over to different