SlideShare una empresa de Scribd logo
1 de 24
An Intro to Test Driven
Development (TDD)
Rob Hale
April 11, 2016
Goals
• Automated testing isn’t (always) TDD
• Where it fits
• Moq
Automated Unit
Testing
What’s a “unit”
• The test operates in isolation
• tests should never depend on each other
Benefits of unit tests over end-to-end tests
• Error localization
• Execution time
• Tighter feedback loop
• Coverage
40x
What’s not a unit test?
I like Michael Feathers’ explanation from Working Effectively with Legacy Code.
It’s not a unit test if:
• It talks to a database
• It communicates across a network
• It touches the file system
• You have to do special things to your environment to run it (like editing a
config file)
DIFFICULT
SCENARIOS TO
UNIT TEST
Closed Object Models
(Sharepoint, Silverlight)
Client – server architecture
- Communicating Across a Network
An out-of-process call
- Includes talking to databases and
Web Services
UI/GUI interaction
Touching the File System
Legacy Code
Requires the Environment to be
configured
Test Driven
Development
The basic cycle
Write a
failing test
Make the
test pass
Refactor
Put another way...
New
require
ment
Run
Tests
Write
new
test
Write
new
test
Write
new
code
Run
Tests
Refact
or
Make it Better
Make it Fail
Make it Work
“When you first start at doing TDD you know what the design should be. You
know what code you want to write. So you write a test that will let you write that
bit of code.
“When you do this you aren't really doing TDD – since you are writing the code
first (even if the code is only in your head )
“It takes some time to realize that you need to focus on the test. Write the test
for the behavior you want - then write the minimal code needed to make it pass
- then let the design emerge through refactoring. Repeat until done.”
--Brian Rasmussen
http://www.slideshare.net/baronslideshare/testdriven-development-tdd
An Exercise in
Test Driven
Development
The idea here is going to be to go
through the exercise of designing a
portion of a new solution in real
time.
After the exercise I want to circle
back and point out the benefits we
gained from the test first approach
which may have been missed had
we coded and then wrote tests.
Principles
• Think About What You Are Trying To Do
• Follow The TDD Cycle
• Never Write New Functionality Without A
Failing Test
- Each test should be for a single
concept
• Continually Make Small, Incremental
Changes
• Keep The System Running At All Times
- No one can make a change that breaks the
system
- Failures Must Be Address Immediately
• Is an activity of the developer
• Test code should be treated the same as
“production”
- maintained
- refactor
- source control
• Experimentation
- Names don’t matter initially
• When you want to change existing code,
first write covering, white box, unit tests
and then use TDD to add new
functionality
• Fix it in the simplest way possible using
as many assumptions as you like
TDD gives you
Design
Confidence
Documentation
Feedback
Realizing quality improvement through test driven development
Metric Description IBM:
Drivers
MSFT:
Windows
MSFT:
MSN
MSFT:
VS
Defect density of
non-TDD team
W X Y Z
Defect density of
team using TDD
0.61W 0.38X 0.24Y 0.09Z
% increase in
coding time
because
of TDD
[Management
estimates]
15-20% 25-35% 15% 25-30%
http://research.microsoft.com/en-us/groups/ese/nagappan_tdd.pdf
Visualized another way...
http://research.microsoft.com/en-us/groups/ese/nagappan_tdd.pdf
Moq
What’s a mock object?
A Test Double object that is pre-programmed with expectations which form a
specification of the calls they are expected to receive
The nice thing about using mocks while doing TDD is we can mock something
that doesn’t actually exist. Just define an interface and mock that. Later on we
can create concrete implementations of the interface (through TDD, of course)
Chicago vs London
Ledger
● Calculate(string expression)
Calculator
● Add
● Subtract
● Multiply
● ...
Based on http://programmers.stackexchange.com/a/123672
ledger.Calculate("5 * 7")
[TestFixture]
public class LedgerTests
{
public static Ledger Ledger { set; get; }
public static int Value { get; set; }
public static Mock<ICalculator> calculator;
[SetUp]
public void LedgerSetup()
{
calculator = new Mock<ICalculator>();
Ledger = new Ledger(calculator.Object);
}
Chicago vs London
[Test]
public void ChicagoStyle()
{
Value = Ledger.Calculate("5 * 7");
Assert.AreEqual(35, Value);
}
The Chicago/State school would have you assert whether the result is 35. The jUnit/nUnit frameworks are generally geared
towards doing this.
Chicago vs London
[Test]
public void ChicagoStyle()
{
Value = Ledger.Calculate("5 * 7");
Assert.AreEqual(35, Value);
}
The Chicago/State school would have you assert whether the result is 35. The jUnit/nUnit frameworks are generally geared
towards doing this.
[Test]
public void LondonStyle()
{
calculator.Verify(calc => calc.Multiply(5, 7), Times.Exactly(1));
}
The London/Interaction school would have you assert whether Calculator.Multiply(5,7) got called. The various
mocking frameworks are useful for this, and it can be very useful if, for example, you don't have ownership of the "Calculator"
object (suppose it is an external component or service that you cannot test directly, but you do know you have to call in a
particular way).
Resources
• http://www.slideshare.net/dehringer/test-driven-development-5785229
• http://www.slideshare.net/baronslideshare/testdriven-development-tdd
• http://research.microsoft.com/en-us/groups/ese/nagappan_tdd.pdf
• http://www.martinfowler.com/articles/mocksArentStubs.html
• Video: Llewellyn Falco & Woody Zuill - Practical Refactoring
• https://youtu.be/aWiwDdx_rdo
• Video: Raymond Lim & Roy Osherove - TDD Pairing Session 1
• https://youtu.be/xX9hfPkA800
• Video: Doc Norton - The Technical Debt Trap
• https://vimeo.com/97507576
Other resources mentioned by attendees
The following resources were mentioned after the presentation. They require
purchase or subscription.
• Play by Play: TDD with Brad Wilson (Pluralsight)
• https://www.pluralsight.com/courses/play-by-play-wilson-tdd
• Automated Testing for Fraidy Cats Like Me with Julie Lerman (Pluralsight)
• https://www.pluralsight.com/courses/automated-testing-fraidy-cats
• Test-Driven Development training by Mike Hill & Joshua Kerievsky (Industrial
Logic)
• https://elearning.industriallogic.com/gh/submit?Action=AlbumContentsAction&album=before
&devLanguage=Java

Más contenido relacionado

La actualidad más candente

Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefAhmed Shreef
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentguestc8093a6
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)nedirtv
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Test-Driven Development (TDD)
Test-Driven Development (TDD)Test-Driven Development (TDD)
Test-Driven Development (TDD)Brian Rasmussen
 
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 2010guest5639fa9
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentJohn Blum
 
Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven developmenttoteb5
 
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
 
Agile Programming Systems # TDD intro
Agile Programming Systems # TDD introAgile Programming Systems # TDD intro
Agile Programming Systems # TDD introVitaliy Kulikov
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Developmentguy_davis
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easierChristian Hujer
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataCory Foy
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentDhaval Dalal
 
Unit testing legacy code
Unit testing legacy codeUnit testing legacy code
Unit testing legacy codeLars Thorup
 
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) CodeOps Technologies LLP
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentMireia Sangalo
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOSPablo Villar
 

La actualidad más candente (20)

Introduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed ShreefIntroduction to TDD (Test Driven development) - Ahmed Shreef
Introduction to TDD (Test Driven development) - Ahmed Shreef
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Test-Driven Development (TDD)
Test-Driven Development (TDD)Test-Driven Development (TDD)
Test-Driven Development (TDD)
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
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
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Scrum and Test-driven development
Scrum and Test-driven developmentScrum and Test-driven development
Scrum and Test-driven development
 
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...
 
Agile Programming Systems # TDD intro
Agile Programming Systems # TDD introAgile Programming Systems # TDD intro
Agile Programming Systems # TDD intro
 
PHPUnit - Unit testing
PHPUnit - Unit testingPHPUnit - Unit testing
PHPUnit - Unit testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier2016 10-04: tdd++: tdd made easier
2016 10-04: tdd++: tdd made easier
 
Getting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and DataGetting Unstuck: Working with Legacy Code and Data
Getting Unstuck: Working with Legacy Code and Data
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Unit testing legacy code
Unit testing legacy codeUnit testing legacy code
Unit testing legacy code
 
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
 
Dependency Injection in iOS
Dependency Injection in iOSDependency Injection in iOS
Dependency Injection in iOS
 

Destacado

ALM Practices - Devops para grandes Organizações
ALM Practices - Devops para grandes OrganizaçõesALM Practices - Devops para grandes Organizações
ALM Practices - Devops para grandes Organizaçõesespecificacoes.com
 
DEV/ops Evolution & Revolution 2016
DEV/ops Evolution & Revolution 2016DEV/ops Evolution & Revolution 2016
DEV/ops Evolution & Revolution 2016Brian Carpio
 
Test Driven Development - The art of fearless programming
Test Driven Development - The art of fearless programmingTest Driven Development - The art of fearless programming
Test Driven Development - The art of fearless programmingChamil Jeewantha
 
Quality management in continuous delivery and dev ops world pm footprints v1
Quality management in continuous delivery and dev ops world  pm footprints v1Quality management in continuous delivery and dev ops world  pm footprints v1
Quality management in continuous delivery and dev ops world pm footprints v1Dr. Anish Cheriyan (PhD)
 
Nbr 8800 lig sold_04
Nbr 8800 lig sold_04Nbr 8800 lig sold_04
Nbr 8800 lig sold_04Edson Silva
 
Lightning Talk: Dev/Ops, Kaizen (lean) meets Agile Development
Lightning Talk: Dev/Ops, Kaizen (lean) meets Agile DevelopmentLightning Talk: Dev/Ops, Kaizen (lean) meets Agile Development
Lightning Talk: Dev/Ops, Kaizen (lean) meets Agile DevelopmentAdam Clater
 
Demystifiying dev ops
Demystifiying dev opsDemystifiying dev ops
Demystifiying dev opsOrganiq
 
Test Driven Development
Test Driven Development Test Driven Development
Test Driven Development Nezir Yürekli
 
Home Depot - From Platform Ops to Dev Enablement
Home Depot - From Platform Ops to Dev EnablementHome Depot - From Platform Ops to Dev Enablement
Home Depot - From Platform Ops to Dev EnablementAnthony McCulley
 
Test Driven Development (TDD) & Continuous Integration (CI)
Test Driven Development (TDD) & Continuous Integration (CI)Test Driven Development (TDD) & Continuous Integration (CI)
Test Driven Development (TDD) & Continuous Integration (CI)Fatkul Amri
 
Dev ops with smell v1.2
Dev ops with smell v1.2Dev ops with smell v1.2
Dev ops with smell v1.2Antons Kranga
 
Deliver Fast and Reliably with Dev Ops and Atlassian
Deliver Fast and Reliably with Dev Ops and AtlassianDeliver Fast and Reliably with Dev Ops and Atlassian
Deliver Fast and Reliably with Dev Ops and AtlassianXpand IT
 

Destacado (16)

ALM Practices - Devops para grandes Organizações
ALM Practices - Devops para grandes OrganizaçõesALM Practices - Devops para grandes Organizações
ALM Practices - Devops para grandes Organizações
 
DEV/ops Evolution & Revolution 2016
DEV/ops Evolution & Revolution 2016DEV/ops Evolution & Revolution 2016
DEV/ops Evolution & Revolution 2016
 
Test Driven Development - The art of fearless programming
Test Driven Development - The art of fearless programmingTest Driven Development - The art of fearless programming
Test Driven Development - The art of fearless programming
 
Atdd half day_new_1_up
Atdd half day_new_1_upAtdd half day_new_1_up
Atdd half day_new_1_up
 
Quality management in continuous delivery and dev ops world pm footprints v1
Quality management in continuous delivery and dev ops world  pm footprints v1Quality management in continuous delivery and dev ops world  pm footprints v1
Quality management in continuous delivery and dev ops world pm footprints v1
 
Nbr 8800 lig sold_04
Nbr 8800 lig sold_04Nbr 8800 lig sold_04
Nbr 8800 lig sold_04
 
Lightning Talk: Dev/Ops, Kaizen (lean) meets Agile Development
Lightning Talk: Dev/Ops, Kaizen (lean) meets Agile DevelopmentLightning Talk: Dev/Ops, Kaizen (lean) meets Agile Development
Lightning Talk: Dev/Ops, Kaizen (lean) meets Agile Development
 
Soldagem 2009 2-emi
Soldagem 2009 2-emiSoldagem 2009 2-emi
Soldagem 2009 2-emi
 
DevOps Overview
DevOps OverviewDevOps Overview
DevOps Overview
 
Demystifiying dev ops
Demystifiying dev opsDemystifiying dev ops
Demystifiying dev ops
 
Test Driven Development
Test Driven Development Test Driven Development
Test Driven Development
 
Home Depot - From Platform Ops to Dev Enablement
Home Depot - From Platform Ops to Dev EnablementHome Depot - From Platform Ops to Dev Enablement
Home Depot - From Platform Ops to Dev Enablement
 
Test Driven Development (TDD) & Continuous Integration (CI)
Test Driven Development (TDD) & Continuous Integration (CI)Test Driven Development (TDD) & Continuous Integration (CI)
Test Driven Development (TDD) & Continuous Integration (CI)
 
Dev ops
Dev opsDev ops
Dev ops
 
Dev ops with smell v1.2
Dev ops with smell v1.2Dev ops with smell v1.2
Dev ops with smell v1.2
 
Deliver Fast and Reliably with Dev Ops and Atlassian
Deliver Fast and Reliably with Dev Ops and AtlassianDeliver Fast and Reliably with Dev Ops and Atlassian
Deliver Fast and Reliably with Dev Ops and Atlassian
 

Similar a VT.NET 20160411: An Intro to Test Driven Development (TDD)

A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)Thierry Gayet
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsOrtus Solutions, Corp
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code cleanBrett Child
 
Advanced A/B Testing at Wix - Aviran Mordo and Sagy Rozman, Wix.com
Advanced A/B Testing at Wix - Aviran Mordo and Sagy Rozman, Wix.comAdvanced A/B Testing at Wix - Aviran Mordo and Sagy Rozman, Wix.com
Advanced A/B Testing at Wix - Aviran Mordo and Sagy Rozman, Wix.comDevOpsDays Tel Aviv
 
Test Driven Development Introduction
Test Driven Development IntroductionTest Driven Development Introduction
Test Driven Development IntroductionNguyen Hai
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Lars Thorup
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql ServerDavid P. Moore
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing SoftwareSteven Smith
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Red Gate Software
 
Testing the Untestable
Testing the UntestableTesting the Untestable
Testing the UntestableMark Baker
 
Test-Driven development; why you should never code without it
Test-Driven development; why you should never code without itTest-Driven development; why you should never code without it
Test-Driven development; why you should never code without itJad Salhani
 
Database continuous integration, unit test and functional test
Database continuous integration, unit test and functional testDatabase continuous integration, unit test and functional test
Database continuous integration, unit test and functional testHarry Zheng
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven DevelopmentMeilan Ou
 

Similar a VT.NET 20160411: An Intro to Test Driven Development (TDD) (20)

A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)A la découverte des google/test (aka gtest)
A la découverte des google/test (aka gtest)
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Into The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applicationsInto The Box 2018 | Assert control over your legacy applications
Into The Box 2018 | Assert control over your legacy applications
 
Keeping code clean
Keeping code cleanKeeping code clean
Keeping code clean
 
Advanced A/B Testing at Wix - Aviran Mordo and Sagy Rozman, Wix.com
Advanced A/B Testing at Wix - Aviran Mordo and Sagy Rozman, Wix.comAdvanced A/B Testing at Wix - Aviran Mordo and Sagy Rozman, Wix.com
Advanced A/B Testing at Wix - Aviran Mordo and Sagy Rozman, Wix.com
 
Test Driven Development Introduction
Test Driven Development IntroductionTest Driven Development Introduction
Test Driven Development Introduction
 
Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)Test and Behaviour Driven Development (TDD/BDD)
Test and Behaviour Driven Development (TDD/BDD)
 
Test Driven Development with Sql Server
Test Driven Development with Sql ServerTest Driven Development with Sql Server
Test Driven Development with Sql Server
 
Improving The Quality of Existing Software
Improving The Quality of Existing SoftwareImproving The Quality of Existing Software
Improving The Quality of Existing Software
 
Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014Get Testing with tSQLt - SQL In The City Workshop 2014
Get Testing with tSQLt - SQL In The City Workshop 2014
 
Unit testing
Unit testingUnit testing
Unit testing
 
Unit tests and TDD
Unit tests and TDDUnit tests and TDD
Unit tests and TDD
 
CNUG TDD June 2014
CNUG TDD June 2014CNUG TDD June 2014
CNUG TDD June 2014
 
Testing the Untestable
Testing the UntestableTesting the Untestable
Testing the Untestable
 
Functional Tests. PHP Unconf 2016
Functional Tests. PHP Unconf 2016Functional Tests. PHP Unconf 2016
Functional Tests. PHP Unconf 2016
 
Test-Driven development; why you should never code without it
Test-Driven development; why you should never code without itTest-Driven development; why you should never code without it
Test-Driven development; why you should never code without it
 
TDD Agile Tour Beirut
TDD  Agile Tour BeirutTDD  Agile Tour Beirut
TDD Agile Tour Beirut
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Database continuous integration, unit test and functional test
Database continuous integration, unit test and functional testDatabase continuous integration, unit test and functional test
Database continuous integration, unit test and functional test
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 

Último

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️Delhi Call girls
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfkalichargn70th171
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providermohitmore19
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...panagenda
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxbodapatigopi8531
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Steffen Staab
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...ICS
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...harshavardhanraghave
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsArshad QA
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerThousandEyes
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsAlberto González Trastoy
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AIABDERRAOUF MEHENNI
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...OnePlan Solutions
 

Último (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
TECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service providerTECUNIQUE: Success Stories: IT Service provider
TECUNIQUE: Success Stories: IT Service provider
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Hand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptxHand gesture recognition PROJECT PPT.pptx
Hand gesture recognition PROJECT PPT.pptx
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
Reassessing the Bedrock of Clinical Function Models: An Examination of Large ...
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS LiveVip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
Vip Call Girls Noida ➡️ Delhi ➡️ 9999965857 No Advance 24HRS Live
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AISyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
SyndBuddy AI 2k Review 2024: Revolutionizing Content Syndication with AI
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
Tech Tuesday-Harness the Power of Effective Resource Planning with OnePlan’s ...
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 

VT.NET 20160411: An Intro to Test Driven Development (TDD)

  • 1. An Intro to Test Driven Development (TDD) Rob Hale April 11, 2016
  • 2. Goals • Automated testing isn’t (always) TDD • Where it fits • Moq
  • 4. What’s a “unit” • The test operates in isolation • tests should never depend on each other
  • 5. Benefits of unit tests over end-to-end tests • Error localization • Execution time • Tighter feedback loop • Coverage
  • 6. 40x
  • 7. What’s not a unit test? I like Michael Feathers’ explanation from Working Effectively with Legacy Code. It’s not a unit test if: • It talks to a database • It communicates across a network • It touches the file system • You have to do special things to your environment to run it (like editing a config file)
  • 8. DIFFICULT SCENARIOS TO UNIT TEST Closed Object Models (Sharepoint, Silverlight) Client – server architecture - Communicating Across a Network An out-of-process call - Includes talking to databases and Web Services UI/GUI interaction Touching the File System Legacy Code Requires the Environment to be configured
  • 9. Test Driven Development The basic cycle Write a failing test Make the test pass Refactor
  • 11. “When you first start at doing TDD you know what the design should be. You know what code you want to write. So you write a test that will let you write that bit of code. “When you do this you aren't really doing TDD – since you are writing the code first (even if the code is only in your head ) “It takes some time to realize that you need to focus on the test. Write the test for the behavior you want - then write the minimal code needed to make it pass - then let the design emerge through refactoring. Repeat until done.” --Brian Rasmussen http://www.slideshare.net/baronslideshare/testdriven-development-tdd
  • 12. An Exercise in Test Driven Development The idea here is going to be to go through the exercise of designing a portion of a new solution in real time. After the exercise I want to circle back and point out the benefits we gained from the test first approach which may have been missed had we coded and then wrote tests.
  • 13. Principles • Think About What You Are Trying To Do • Follow The TDD Cycle • Never Write New Functionality Without A Failing Test - Each test should be for a single concept • Continually Make Small, Incremental Changes • Keep The System Running At All Times - No one can make a change that breaks the system - Failures Must Be Address Immediately • Is an activity of the developer • Test code should be treated the same as “production” - maintained - refactor - source control • Experimentation - Names don’t matter initially • When you want to change existing code, first write covering, white box, unit tests and then use TDD to add new functionality • Fix it in the simplest way possible using as many assumptions as you like
  • 15. Realizing quality improvement through test driven development Metric Description IBM: Drivers MSFT: Windows MSFT: MSN MSFT: VS Defect density of non-TDD team W X Y Z Defect density of team using TDD 0.61W 0.38X 0.24Y 0.09Z % increase in coding time because of TDD [Management estimates] 15-20% 25-35% 15% 25-30% http://research.microsoft.com/en-us/groups/ese/nagappan_tdd.pdf
  • 17. Moq
  • 18. What’s a mock object? A Test Double object that is pre-programmed with expectations which form a specification of the calls they are expected to receive The nice thing about using mocks while doing TDD is we can mock something that doesn’t actually exist. Just define an interface and mock that. Later on we can create concrete implementations of the interface (through TDD, of course)
  • 19. Chicago vs London Ledger ● Calculate(string expression) Calculator ● Add ● Subtract ● Multiply ● ... Based on http://programmers.stackexchange.com/a/123672 ledger.Calculate("5 * 7")
  • 20. [TestFixture] public class LedgerTests { public static Ledger Ledger { set; get; } public static int Value { get; set; } public static Mock<ICalculator> calculator; [SetUp] public void LedgerSetup() { calculator = new Mock<ICalculator>(); Ledger = new Ledger(calculator.Object); }
  • 21. Chicago vs London [Test] public void ChicagoStyle() { Value = Ledger.Calculate("5 * 7"); Assert.AreEqual(35, Value); } The Chicago/State school would have you assert whether the result is 35. The jUnit/nUnit frameworks are generally geared towards doing this.
  • 22. Chicago vs London [Test] public void ChicagoStyle() { Value = Ledger.Calculate("5 * 7"); Assert.AreEqual(35, Value); } The Chicago/State school would have you assert whether the result is 35. The jUnit/nUnit frameworks are generally geared towards doing this. [Test] public void LondonStyle() { calculator.Verify(calc => calc.Multiply(5, 7), Times.Exactly(1)); } The London/Interaction school would have you assert whether Calculator.Multiply(5,7) got called. The various mocking frameworks are useful for this, and it can be very useful if, for example, you don't have ownership of the "Calculator" object (suppose it is an external component or service that you cannot test directly, but you do know you have to call in a particular way).
  • 23. Resources • http://www.slideshare.net/dehringer/test-driven-development-5785229 • http://www.slideshare.net/baronslideshare/testdriven-development-tdd • http://research.microsoft.com/en-us/groups/ese/nagappan_tdd.pdf • http://www.martinfowler.com/articles/mocksArentStubs.html • Video: Llewellyn Falco & Woody Zuill - Practical Refactoring • https://youtu.be/aWiwDdx_rdo • Video: Raymond Lim & Roy Osherove - TDD Pairing Session 1 • https://youtu.be/xX9hfPkA800 • Video: Doc Norton - The Technical Debt Trap • https://vimeo.com/97507576
  • 24. Other resources mentioned by attendees The following resources were mentioned after the presentation. They require purchase or subscription. • Play by Play: TDD with Brad Wilson (Pluralsight) • https://www.pluralsight.com/courses/play-by-play-wilson-tdd • Automated Testing for Fraidy Cats Like Me with Julie Lerman (Pluralsight) • https://www.pluralsight.com/courses/automated-testing-fraidy-cats • Test-Driven Development training by Mike Hill & Joshua Kerievsky (Industrial Logic) • https://elearning.industriallogic.com/gh/submit?Action=AlbumContentsAction&album=before &devLanguage=Java

Notas del editor

  1. I’m coming at this as a fellow traveller - not an expert
  2. Understand the differences between automated testing and test driven development Understand where the value of test driven development lies Introduction to the Moq framework
  3. Error localization: “As tests get further from what they test, it’s harder to determine what a test failure means.” Michael Feathers Working Effectively with Legacy Code Execution time: Large tests take longer to run. Longer to run means not run as frequently (if at all) Tighter feedback loop: related to execution time - don’t have to wait as long to know if you’re code changes broke anything Coverage: It’s easier to test the different execution paths in a unit test. Think about testing a new feature in a large, existing end-to-end test versus adding a unit test to exercise it
  4. “Maintenance fixes and “small” code changes may be nearly 40 times more error prone than new development (Managing the Software Process, Watts S. Humphrey, Addison-Wesley, 1989)... By continuously running automated test cases, one can find out whether a change breaks the existing system early on, rather than leading to a late discovery.” - Realizing quality improvement through test driven development: results and experiences of four industrial teams, Nachiappan Nagappan & E. Michael Maximilien & Thirumalesh Bhat & Laurie Williams, Springer Science + Business Media, LLC, 2008
  5. Tests like these aren’t bad. There may be value in writing them. They just aren’t unit tests. Feathers’ definition of a unit test is driven by two properties: Does the test run fast? A unit test that takes 1/10th of a second is too long. 3,000 classes w/ 10 tests each at that speed is about an hour of test time Does it help localize errors quickly?
  6. Notice entry point is a new requirement not a new feature This is a tight loop - short iterations are important We’re only producing code needed for the current test The goal is to produce working clean code that fulfills the requirement
  7. Though poorly worded, the thrust of this quote is helpful.
  8. Add a comment for tests we want to circle back to that aren’t happy path (like in video where passing in coordinates that don’t correspond to a valid board position) Don’t do calculations in your tests b/c it often means you’re recreating a code calculation - you could just be recreating a bug but the test will pass Reminder - NUnit 2.6.4 - My version of R# won’t work with NUnit 3.x
  9. It’s mostly about design Confidence in changes Is documentation by example Immediate feedback
  10. Gerard Meszaros uses the term Test Double as the generic term for any kind of pretend object used in place of a real object for testing purposes. The name comes from the notion of a Stunt Double in movies. He then defined four particular kinds of double: Dummy objects are passed around but never actually used. Usually they are just used to fill parameter lists. Fake objects actually have working implementations, but usually take some shortcut which makes them not suitable for production (an in memory database is a good example). Stubs provide canned answers to calls made during the test, usually not responding at all to anything outside what's programmed in for the test. Stubs may also record information about calls, such as an email gateway stub that remembers the messages it 'sent', or maybe only how many messages it 'sent'. Mocks are what we are talking about here: objects pre-programmed with expectations which form a specification of the calls they are expected to receive. Only mocks insist upon behavior verification.
  11. Suppose you have class called "ledger" a method called "calculate" that uses a "Calculator" to do different types of calculations depending on the arguments passed to "calculate", for example "multiply(x, y)" or "subtract(x, y)". Now, suppose you want to test what happens when you call ledger.calculate("5 * 7") The Chicago/State school would have you assert whether the result is 35. The jUnit/nUnit frameworks are generally geared towards doing this. The London/Interaction school would have you assert whether Calculator.multiply(5,7) got called. The various mocking frameworks are useful for this, and it can be very useful if, for example, you don't have ownership of the "Calculator" object (suppose it is an external component or service that you cannot test directly, but you do know you have to call in a particular way).
  12. This is the base test class. Don’t worry about the syntax of the mock… just understand what it is.
  13. The Chicago/State school would have you assert whether the result is 35. The jUnit/nUnit frameworks are generally geared towards doing this.
  14. The Chicago/State school would have you assert whether the result is 35. The jUnit/nUnit frameworks are generally geared towards doing this.