SlideShare una empresa de Scribd logo
1 de 29
Dennis van der Stelt

Introduction in the TDD Mantra
Session Code: NE.17
Introduction
• Class-A
–
–
–
–

Kennisprovider
Microsoft development
Training / Coaching
www.class-a.nl

• Dennis van der Stelt
– Trainer / Coach
– Weblog at http://bloggingabout.net/blogs/dennis/
Agenda
•
•
•
•
•
•
•
•

A quick introduction into unit testing
Test Driven Development mantra
Refactoring
Benefits of Test Driven Development
Demo
Key rules of Test Driven Development
Mocking / Stubbing
Legacy code
A quick introduction
Unit testing
1. Automated testing
2. Facilitates change
3. Simplifies integration
4. Documentation
unit testing isn’t about just testing code
it‘s about allowing you to
determine when behavior changes
TDD Mantra
RED

GREEN
I’M TEST-DRIVEN

•
•
•
•

Write the test
Write the code
Refactor
Repeat

REFACTOR
TDD Mantra
Where to begin?
• Work from specification (or notes, or napkin)
• Create a list of tests
• Pick the simplest one
• Make test, make code
• Refactor

• Find a bug? Create the test that would’ve
caught it!
Test Driven Development
...is not about testing.
• It’s about design
• It’s about unambigious requirements
• It’s also about simplicity and YAGNI
Simplicity is more complicated then you think. But it’s well worth it.
Ron Jeffries, Extreme Programming Installed, 2001
Test Driven Development
...is about simple design that
1.
2.
3.
4.

Runs all tests
Reveals all intention
Has no duplication
Has the fewest number of classes and methods
Test Driven Development
“The act of writing a unit test is more an act of design then of verification”

- Robert C. Martin
“Test-driven development seeks specification, not validation, letting you think
through your design before you write your functional code”

- Scott Ambler
“Test-Driven Development is a powerful way to produce well designed code
with fewer defects”

- Martin Fowler
“Fewer defects, less debugging, more confidence, better design, and higher
productivity in my programming practice”

- Kent Beck
Benefits of TDD (1/3)
Benefits on your design & code
• Exposes design flaws & invalid assumptions
• Simpler class hierarchies
• Less code, smaller functions
• Less conditional code
• Faster development time

• Tests are both design & documentation
Benefits of TDD (2/3)
Benefits on your tests & bugs
• Tests cover *everything*
• Bugs found earlier & faster
• Bugs reproduced more easily
• Less (difficult) debugging
Benefits of TDD (3/3)
Cost of change

Test-Driven Development embraces change!
Waterfall
Cons of TDD
•
•
•
•

Needs practice, but you’ll learn to love it!
Needs discipline
Need to know OODP
Scares away managers
Bowling game
First a quick design session…
Bowling game
0 4
4

2 4
10

4 3
17

4 + (2+4)

•
•
•
•

6
30

3 2
35

55

9
65

0 0
65

9 0
74

7 2
83

17 + (6+4+3) 35 + (10+9+1) + 1 + 0)
55 + (9

10 frames, each holds 2 throws
Spare: 10 pins 2nd try, next throw added extra
Strike: 10 pins in 1st try, score next frame added
10th frame spare or strike,
player can make extra balls to complete frame.
Quick design sessions
next frame

Frame

Game
+roll(pins : int)
+score() : int

The score for spare or strike
depends on the frame’s succesor

10

+score() : int

Roll
1..2

-pins : int

1

We clearlyfunction must A game has ten frames. A frame has 1 or 2 roles.
The score need the Game class.
iterate
through all the frames, and
calculate all their scores.
tenth frame

The tenth frame has two or three roles.
It is different from all the other frames.
Bowling game
Finally some code!
Key rules of TDD
A test is no unit test if…
• …it talks to a database
• …it communicates across the network
• …it touches the file system
• …it can’t run at the same time as other tests
• …you have to perform actions to run the tests
(ex. configuration change)
How to isolate your code
How to isolate your code

database

logging
service

remote
server
How to isolate your code
Mocks & Stubs
A mock or stub is a stunt double for…
• …an object outside your unit
• …an external object (database)
• …a complex object(s)
• …a not yet developed object

Mocking & Stubbing are different things!
Isolation framework
[TestMethod]
public void Does_AllowDependencyInjection_When_CreatingInstance()
{
// Arrange
var fake = Isolate.Fake.Instance<ICustomerRepository>();
Customer cust = new Customer();
// Act
BusinessAction ba = new BusinessAction(fake);
ba.PerformSomeSortOfAction(cust);

// Assert
Isolate.Verify.
WasCalledWithExactArguments(() => fake.SaveChanges(cust));
}
Legacy code
What is legacy code?
Wikipedia : Legacy code is source code that relates
to a no-longer supported or manufactured
operating system or other computer system.

Why is legacy code bad?
• The previous developer isn’t there to explain it.
• It takes time to learn the code.
• It’s not easy to change the code.
• You might break some part of the application
you didn’t even touch.
Legacy code
Now imagine...
Without a tests,
• You’re developer on unitproject,
What if you have unit tests? as we speak!
you’re writing legacy code
• You get sick for two weeks,
• Yourhave tests to explain the code
You code needs to be completed,
• Another developer comes in.
You have tests to learn the code
© Michael Feathers – Working Effectively with Legacy Code

You have tests to verify what you did works,
and did not break any other part of the
application.

- The previous developer isn’t there to explain it.
- It takes time to learn the code.
- It’s not easy to change the code.
- You might break some part of the application you didn’t even touch.
Conclusion:

WRITE UNIT TESTS!
and do it the right way using Test-Driven Development.
Thank you for your attention
• Dennis van der Stelt
– Dennis@BloggingAbout.NET
– http://twitter.com/dvdstelt/
– http://bloggingabout.net/blogs/dennis/
Resources to more information can be found here, incl. this slidedeck.
Evaluation form
Vul je evaluatieformulier in en maak kans
op een van de prachtige prijzen!!
Fill out your evaluation form and win one of
the great prizes!!

Session Code: NE.17

Más contenido relacionado

La actualidad más candente

Testing and TDD - KoJUG
Testing and TDD - KoJUGTesting and TDD - KoJUG
Testing and TDD - KoJUGlburdz
 
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
 
Exception Handling
Exception Handling  Exception Handling
Exception Handling RatnaJava
 
Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)jaxLondonConference
 
Test Drive Development
Test Drive DevelopmentTest Drive Development
Test Drive Developmentsatya sudheer
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test PatternsFrank Appel
 
@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPECWojciech Bulaty
 
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 DevelopmentShawn Jones
 
Test driven-development
Test driven-developmentTest driven-development
Test driven-developmentDavid Paluy
 
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 boardRuth Sperer
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In ActionJon Kruger
 
Test Driven Development (C#)
Test Driven Development (C#)Test Driven Development (C#)
Test Driven Development (C#)Alan Dean
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testingpleeps
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven DevelopmentConsulthinkspa
 
TDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD TechniquesTDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD TechniquesDavid Rodenas
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven DevelopmentFerdous Mahmud Shaon
 
TDD: Develop, Refactor and Release With Confidence
TDD: Develop, Refactor and Release With ConfidenceTDD: Develop, Refactor and Release With Confidence
TDD: Develop, Refactor and Release With ConfidenceMehdi Valikhani
 
Test driven development
Test driven developmentTest driven development
Test driven developmentMarcelo Cure
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Thomas Weller
 

La actualidad más candente (20)

Testing and TDD - KoJUG
Testing and TDD - KoJUGTesting and TDD - KoJUG
Testing and TDD - KoJUG
 
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
 
Exception Handling
Exception Handling  Exception Handling
Exception Handling
 
Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)Java Testing With Spock - Ken Sipe (Trexin Consulting)
Java Testing With Spock - Ken Sipe (Trexin Consulting)
 
Test Drive Development
Test Drive DevelopmentTest Drive Development
Test Drive Development
 
Clean Unit Test Patterns
Clean Unit Test PatternsClean Unit Test Patterns
Clean Unit Test Patterns
 
@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC@LinkingNote annotation in YATSPEC
@LinkingNote annotation in YATSPEC
 
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
 
Exploratory testing workshop
Exploratory testing workshopExploratory testing workshop
Exploratory testing workshop
 
Test driven-development
Test driven-developmentTest driven-development
Test driven-development
 
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
 
Test-Driven Development In Action
Test-Driven Development In ActionTest-Driven Development In Action
Test-Driven Development In Action
 
Test Driven Development (C#)
Test Driven Development (C#)Test Driven Development (C#)
Test Driven Development (C#)
 
Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD TechniquesTDD CrashCourse Part3: TDD Techniques
TDD CrashCourse Part3: TDD Techniques
 
Getting started with Test Driven Development
Getting started with Test Driven DevelopmentGetting started with Test Driven Development
Getting started with Test Driven Development
 
TDD: Develop, Refactor and Release With Confidence
TDD: Develop, Refactor and Release With ConfidenceTDD: Develop, Refactor and Release With Confidence
TDD: Develop, Refactor and Release With Confidence
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
Introduction to testing with MSTest, Visual Studio, and Team Foundation Serve...
 

Destacado

Destacado (11)

Distributed Systems principles
Distributed Systems principlesDistributed Systems principles
Distributed Systems principles
 
LIDNUG : Reliable applications with messaging
LIDNUG : Reliable applications with messagingLIDNUG : Reliable applications with messaging
LIDNUG : Reliable applications with messaging
 
Building reliable applications with messaging
Building reliable applications with messagingBuilding reliable applications with messaging
Building reliable applications with messaging
 
Death of the batch job - NServiceBus Sagas
Death of the batch job - NServiceBus SagasDeath of the batch job - NServiceBus Sagas
Death of the batch job - NServiceBus Sagas
 
Een andere kijk op Microservices
Een andere kijk op MicroservicesEen andere kijk op Microservices
Een andere kijk op Microservices
 
Death of the batch job
Death of the batch jobDeath of the batch job
Death of the batch job
 
AppFabric Velocity
AppFabric VelocityAppFabric Velocity
AppFabric Velocity
 
Silverlight & WCF RIA
Silverlight & WCF RIASilverlight & WCF RIA
Silverlight & WCF RIA
 
Distributed Systems Design
Distributed Systems DesignDistributed Systems Design
Distributed Systems Design
 
Duplicating data or replicating data in Micro Services
Duplicating data or replicating data in Micro ServicesDuplicating data or replicating data in Micro Services
Duplicating data or replicating data in Micro Services
 
Distributed Systems Principles
Distributed Systems PrinciplesDistributed Systems Principles
Distributed Systems Principles
 

Similar a Test Driven Development

TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)ssusercaf6c1
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)Nacho Cougil
 
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
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekNacho Cougil
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)Nacho Cougil
 
TDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - OpensouthcodeTDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - OpensouthcodeNacho Cougil
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven DevelopmentPablo Villar
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Jason Tice
 
TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012Alan Christensen
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0Ganesh Kondal
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019Paulo Clavijo
 
Take Pride in Your Code - Test-Driven Development
Take Pride in Your Code - Test-Driven DevelopmentTake Pride in Your Code - Test-Driven Development
Take Pride in Your Code - Test-Driven DevelopmentBADR
 
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
 
Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testingdn
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best PracticesTomaš Maconko
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplaceDonny Wals
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplaceDonny Wals
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)Rob Hale
 

Similar a Test Driven Development (20)

TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
TDD - Seriously, try it! - Trójmiasto Java User Group (17th May '23)
 
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
TDD - Seriously, try it! - Trjjmiasto JUG (17th May '23)
 
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)
 
TDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech WeekTDD - Seriously, try it! - Bucarest Tech Week
TDD - Seriously, try it! - Bucarest Tech Week
 
TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)TDD - Seriously, try it! (updated '22)
TDD - Seriously, try it! (updated '22)
 
TDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - OpensouthcodeTDD - Seriously, try it! - Opensouthcode
TDD - Seriously, try it! - Opensouthcode
 
iOS Test-Driven Development
iOS Test-Driven DevelopmentiOS Test-Driven Development
iOS Test-Driven Development
 
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
Joe Cisar - Everything I Know About TDD - Agile Midwest 2019
 
TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012TDD - Christchurch APN May 2012
TDD - Christchurch APN May 2012
 
Test driven development v1.0
Test driven development v1.0Test driven development v1.0
Test driven development v1.0
 
TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019TDD and Simple Design Workshop - Session 1 - March 2019
TDD and Simple Design Workshop - Session 1 - March 2019
 
Take Pride in Your Code - Test-Driven Development
Take Pride in Your Code - Test-Driven DevelopmentTake Pride in Your Code - Test-Driven Development
Take Pride in Your Code - Test-Driven Development
 
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...
 
Behaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About TestingBehaviour Driven Development and Thinking About Testing
Behaviour Driven Development and Thinking About Testing
 
Unit Testing Best Practices
Unit Testing Best PracticesUnit Testing Best Practices
Unit Testing Best Practices
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplace
 
Adopting tdd in the workplace
Adopting tdd in the workplaceAdopting tdd in the workplace
Adopting tdd in the workplace
 
Testing automaton
Testing automatonTesting automaton
Testing automaton
 
Testing Automaton - CFSummit 2016
Testing Automaton - CFSummit 2016Testing Automaton - CFSummit 2016
Testing Automaton - CFSummit 2016
 
VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)VT.NET 20160411: An Intro to Test Driven Development (TDD)
VT.NET 20160411: An Intro to Test Driven Development (TDD)
 

Más de Dennis van der Stelt

Más de Dennis van der Stelt (7)

Change your architecture during deployment
Change your architecture during deploymentChange your architecture during deployment
Change your architecture during deployment
 
Dealing with eventual consistency
Dealing with eventual consistencyDealing with eventual consistency
Dealing with eventual consistency
 
Dealing with eventual consistency
Dealing with eventual consistencyDealing with eventual consistency
Dealing with eventual consistency
 
Continuous integration
Continuous integrationContinuous integration
Continuous integration
 
App fabric introduction
App fabric introductionApp fabric introduction
App fabric introduction
 
SOLID Principles part 2
SOLID Principles part 2SOLID Principles part 2
SOLID Principles part 2
 
SOLID Principles part 1
SOLID Principles part 1SOLID Principles part 1
SOLID Principles part 1
 

Último

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rick Flair
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsNathaniel Shimoni
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Último (20)

TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...Rise of the Machines: Known As Drones...
Rise of the Machines: Known As Drones...
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Time Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directionsTime Series Foundation Models - current state and future directions
Time Series Foundation Models - current state and future directions
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Test Driven Development

  • 1. Dennis van der Stelt Introduction in the TDD Mantra Session Code: NE.17
  • 2. Introduction • Class-A – – – – Kennisprovider Microsoft development Training / Coaching www.class-a.nl • Dennis van der Stelt – Trainer / Coach – Weblog at http://bloggingabout.net/blogs/dennis/
  • 3. Agenda • • • • • • • • A quick introduction into unit testing Test Driven Development mantra Refactoring Benefits of Test Driven Development Demo Key rules of Test Driven Development Mocking / Stubbing Legacy code
  • 4. A quick introduction Unit testing 1. Automated testing 2. Facilitates change 3. Simplifies integration 4. Documentation
  • 5. unit testing isn’t about just testing code it‘s about allowing you to determine when behavior changes
  • 6. TDD Mantra RED GREEN I’M TEST-DRIVEN • • • • Write the test Write the code Refactor Repeat REFACTOR
  • 7. TDD Mantra Where to begin? • Work from specification (or notes, or napkin) • Create a list of tests • Pick the simplest one • Make test, make code • Refactor • Find a bug? Create the test that would’ve caught it!
  • 8. Test Driven Development ...is not about testing. • It’s about design • It’s about unambigious requirements • It’s also about simplicity and YAGNI Simplicity is more complicated then you think. But it’s well worth it. Ron Jeffries, Extreme Programming Installed, 2001
  • 9. Test Driven Development ...is about simple design that 1. 2. 3. 4. Runs all tests Reveals all intention Has no duplication Has the fewest number of classes and methods
  • 10. Test Driven Development “The act of writing a unit test is more an act of design then of verification” - Robert C. Martin “Test-driven development seeks specification, not validation, letting you think through your design before you write your functional code” - Scott Ambler “Test-Driven Development is a powerful way to produce well designed code with fewer defects” - Martin Fowler “Fewer defects, less debugging, more confidence, better design, and higher productivity in my programming practice” - Kent Beck
  • 11. Benefits of TDD (1/3) Benefits on your design & code • Exposes design flaws & invalid assumptions • Simpler class hierarchies • Less code, smaller functions • Less conditional code • Faster development time • Tests are both design & documentation
  • 12. Benefits of TDD (2/3) Benefits on your tests & bugs • Tests cover *everything* • Bugs found earlier & faster • Bugs reproduced more easily • Less (difficult) debugging
  • 13. Benefits of TDD (3/3) Cost of change Test-Driven Development embraces change! Waterfall
  • 14. Cons of TDD • • • • Needs practice, but you’ll learn to love it! Needs discipline Need to know OODP Scares away managers
  • 15. Bowling game First a quick design session…
  • 16. Bowling game 0 4 4 2 4 10 4 3 17 4 + (2+4) • • • • 6 30 3 2 35 55 9 65 0 0 65 9 0 74 7 2 83 17 + (6+4+3) 35 + (10+9+1) + 1 + 0) 55 + (9 10 frames, each holds 2 throws Spare: 10 pins 2nd try, next throw added extra Strike: 10 pins in 1st try, score next frame added 10th frame spare or strike, player can make extra balls to complete frame.
  • 17. Quick design sessions next frame Frame Game +roll(pins : int) +score() : int The score for spare or strike depends on the frame’s succesor 10 +score() : int Roll 1..2 -pins : int 1 We clearlyfunction must A game has ten frames. A frame has 1 or 2 roles. The score need the Game class. iterate through all the frames, and calculate all their scores. tenth frame The tenth frame has two or three roles. It is different from all the other frames.
  • 19. Key rules of TDD A test is no unit test if… • …it talks to a database • …it communicates across the network • …it touches the file system • …it can’t run at the same time as other tests • …you have to perform actions to run the tests (ex. configuration change)
  • 20. How to isolate your code
  • 21. How to isolate your code database logging service remote server
  • 22. How to isolate your code
  • 23. Mocks & Stubs A mock or stub is a stunt double for… • …an object outside your unit • …an external object (database) • …a complex object(s) • …a not yet developed object Mocking & Stubbing are different things!
  • 24. Isolation framework [TestMethod] public void Does_AllowDependencyInjection_When_CreatingInstance() { // Arrange var fake = Isolate.Fake.Instance<ICustomerRepository>(); Customer cust = new Customer(); // Act BusinessAction ba = new BusinessAction(fake); ba.PerformSomeSortOfAction(cust); // Assert Isolate.Verify. WasCalledWithExactArguments(() => fake.SaveChanges(cust)); }
  • 25. Legacy code What is legacy code? Wikipedia : Legacy code is source code that relates to a no-longer supported or manufactured operating system or other computer system. Why is legacy code bad? • The previous developer isn’t there to explain it. • It takes time to learn the code. • It’s not easy to change the code. • You might break some part of the application you didn’t even touch.
  • 26. Legacy code Now imagine... Without a tests, • You’re developer on unitproject, What if you have unit tests? as we speak! you’re writing legacy code • You get sick for two weeks, • Yourhave tests to explain the code You code needs to be completed, • Another developer comes in. You have tests to learn the code © Michael Feathers – Working Effectively with Legacy Code You have tests to verify what you did works, and did not break any other part of the application. - The previous developer isn’t there to explain it. - It takes time to learn the code. - It’s not easy to change the code. - You might break some part of the application you didn’t even touch.
  • 27. Conclusion: WRITE UNIT TESTS! and do it the right way using Test-Driven Development.
  • 28. Thank you for your attention • Dennis van der Stelt – Dennis@BloggingAbout.NET – http://twitter.com/dvdstelt/ – http://bloggingabout.net/blogs/dennis/ Resources to more information can be found here, incl. this slidedeck.
  • 29. Evaluation form Vul je evaluatieformulier in en maak kans op een van de prachtige prijzen!! Fill out your evaluation form and win one of the great prizes!! Session Code: NE.17