SlideShare a Scribd company logo
What is Test-Driven Development (TDD)?
TDD is the practice of writing a unit test before writing any code. This can be done relatively quickly, with
the developer writing the test, then writing the code, and then running the test, all in small increments.
TDD ensures the code is consistently refactored for a better design. However, TDD isn’t a replacement
for regression suites, design specifications, QA, or code reviews.

TDD = TFD (Test Fi rst Desi gn) + Refa cto r
Contrary to popular opinion, Agile is not cowboy coding. If there’s no BDUF (Big Design Up Front),
how do you ensure your coding process has some structure? TDD is one answer.

What’s the goal of TDD?
To write “clean code that works”. (According to Ron Jeffries, http://xprogramming.com/index.php.)

What are the benefits of TDD?
•	 Better code design
•	 Earlier defect detection
•	 Fewer defects in production releases
•	 Significant drop in defect density
•	 Disciplined, quality-focused coding practices

e
rit hat
W t
t
e s fa i l s
t

Cha
n
c od g e
e
y
V e r i fs t s
e
a l l ta s s
p
TDD Activities
Step
1

2

Working with Legacy Code
You can use TDD with your existing legacy code, but
it can be overwhelming if the code wasn’t designed to be
testable. Following are a few tips to help you get started:

Activity
Write a test to verify new or changed functionality.

1.	 Refactor the code you are changing so it is testable.

Run all tests and verify the new one fails (since it hasn’t been implemented yet).

2.	 Look for “code smells”—symptoms in the source code
	 that could indicate a deeper problem.
3.	 Don’t worry about code coverage in old code.

3

Change the code just enough so that all tests pass. Your goal at this stage is to pass the test,
so the code may not be elegant.

4

Refactor as needed to clean up the code. Verify all tests still pass after the refactor.

5

Repeat the process for the next change.

Writing a Good Unit Test

Sample Unit Test: Constructor Default Values

Good unit tests are the backbone of successful TDD.
Keep the following in mind as you write unit tests:
•	 Each unit test should be independent.
•	 Each unit test should test one aspect or behavior and
	 document the expected behavior.
•	 Each unit test should not verify too much functionality.
•	 Each unit test should not be dependent on interface.

Cincinnati • London • Munich • Melbourne • Johannesburg

To learn more, check out Working Effectively with Legacy
Code, by Michael Feathers.

www.seapine.com © 2014, Seapine Software, Inc. All rights reserved.

/* The purpose of this test is to verify the default values
branchid should be INVALID_RECORD_ID, recursive should be set to true
*/
TEST(SCMWorkingDirTestSuite_Constructor_DefaultValues)
{
CSCMWorkingDirListObj workDir;
CHECK_EQUAL(INVALID_RECORD_ID, workDir.GetBranchID());
CHECK_EQUAL(static_cast<Boolean>(TRUE), workDir.GetRecursive());
};

More Related Content

What's hot

TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
Lim Chanmann
 
Test driven development
Test driven developmentTest driven development
Test driven development
Harry Potter
 

What's hot (17)

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)
 
Tdd
TddTdd
Tdd
 
TDD (Test Driven Design)
TDD (Test Driven Design)TDD (Test Driven Design)
TDD (Test Driven Design)
 
TDD - Test Driven Development
TDD - Test Driven DevelopmentTDD - Test Driven Development
TDD - Test Driven Development
 
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
 
Presentation Test Driven Development
Presentation Test Driven DevelopmentPresentation Test Driven Development
Presentation Test Driven Development
 
Tdd red-green-refactor
Tdd red-green-refactorTdd red-green-refactor
Tdd red-green-refactor
 
TDD
TDDTDD
TDD
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Agile Programming Systems # TDD intro
Agile Programming Systems # TDD introAgile Programming Systems # TDD intro
Agile Programming Systems # TDD intro
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
TDD with RSpec
TDD with RSpecTDD with RSpec
TDD with RSpec
 
Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.Unit testing & TDD concepts with best practice guidelines.
Unit testing & TDD concepts with best practice guidelines.
 
TDD and Unit Testing in Golang
TDD and Unit Testing in GolangTDD and Unit Testing in Golang
TDD and Unit Testing in Golang
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Test drive on driven development process
Test drive on driven development processTest drive on driven development process
Test drive on driven development process
 
Test driven development
Test driven developmentTest driven development
Test driven development
 

Similar to Test-Driven Development Reference Card

Test driven development
Test driven developmentTest driven development
Test driven development
Luis Goldster
 
Test driven development
Test driven developmentTest driven development
Test driven development
Tony Nguyen
 
Test driven development
Test driven developmentTest driven development
Test driven development
Young Alista
 
Test driven development
Test driven developmentTest driven development
Test driven development
James Wong
 
Test driven development
Test driven developmentTest driven development
Test driven development
Fraboni Ec
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx
AmalEldhose2
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
Meilan Ou
 

Similar to Test-Driven Development Reference Card (20)

Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
Test driven development
Test driven developmentTest driven development
Test driven development
 
{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx{10.0} Test Driven Development.pptx
{10.0} Test Driven Development.pptx
 
The Essentials Of Test Driven Development
The Essentials Of Test Driven Development The Essentials Of Test Driven Development
The Essentials Of Test Driven Development
 
TDD in Agile
TDD in AgileTDD in Agile
TDD in Agile
 
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
 
xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012xUnit and TDD: Why and How in Enterprise Software, August 2012
xUnit and TDD: Why and How in Enterprise Software, August 2012
 
Understanding Why Testing is Importaint
Understanding Why Testing is ImportaintUnderstanding Why Testing is Importaint
Understanding Why Testing is Importaint
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Tdd
TddTdd
Tdd
 
Test Driven Development and Automation
Test Driven Development and AutomationTest Driven Development and Automation
Test Driven Development and Automation
 
Android tdd
Android tddAndroid tdd
Android tdd
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 
Python: Object-oriented Testing
Python: Object-oriented TestingPython: Object-oriented Testing
Python: Object-oriented Testing
 
Test Driven Development - Overview and Adoption
Test Driven Development - Overview and AdoptionTest Driven Development - Overview and Adoption
Test Driven Development - Overview and Adoption
 
Test-Driven Development
Test-Driven DevelopmentTest-Driven Development
Test-Driven Development
 
Test Driven Development
Test Driven DevelopmentTest Driven Development
Test Driven Development
 

More from Seapine Software

Traceability Trends in Medical Device Development
Traceability Trends in Medical Device DevelopmentTraceability Trends in Medical Device Development
Traceability Trends in Medical Device Development
Seapine Software
 
FMEA RCA Risk Management webinar
FMEA RCA Risk Management webinarFMEA RCA Risk Management webinar
FMEA RCA Risk Management webinar
Seapine Software
 
Seapine driverless car safety infographic
Seapine driverless car safety infographicSeapine driverless car safety infographic
Seapine driverless car safety infographic
Seapine Software
 
Seapine Scrum Reference Card
Seapine Scrum Reference CardSeapine Scrum Reference Card
Seapine Scrum Reference Card
Seapine Software
 
Webinar - Maximizing Requirements Value Throughout the Product Lifecycle
Webinar - Maximizing Requirements Value Throughout the Product Lifecycle Webinar - Maximizing Requirements Value Throughout the Product Lifecycle
Webinar - Maximizing Requirements Value Throughout the Product Lifecycle
Seapine Software
 
Medical Device Development - Automating Traceability and Documentation
Medical Device Development - Automating Traceability and DocumentationMedical Device Development - Automating Traceability and Documentation
Medical Device Development - Automating Traceability and Documentation
Seapine Software
 
FDA Expectations for Traceability in Device & Diagnostic Design
FDA Expectations for Traceability in Device & Diagnostic DesignFDA Expectations for Traceability in Device & Diagnostic Design
FDA Expectations for Traceability in Device & Diagnostic Design
Seapine Software
 
Take the Pain (and Weekends) Out of Test Case Management
Take the Pain (and Weekends) Out of Test Case ManagementTake the Pain (and Weekends) Out of Test Case Management
Take the Pain (and Weekends) Out of Test Case Management
Seapine Software
 
Understanding the Business Case for Agile
Understanding the Business Case for AgileUnderstanding the Business Case for Agile
Understanding the Business Case for Agile
Seapine Software
 
Agile at Seapine (University of Cincinnati 2011)
Agile at Seapine (University of Cincinnati 2011)Agile at Seapine (University of Cincinnati 2011)
Agile at Seapine (University of Cincinnati 2011)
Seapine Software
 

More from Seapine Software (20)

Breaking the Barriers to Agile Adoption in Safety- and Quality-Critical Envir...
Breaking the Barriers to Agile Adoption in Safety- and Quality-Critical Envir...Breaking the Barriers to Agile Adoption in Safety- and Quality-Critical Envir...
Breaking the Barriers to Agile Adoption in Safety- and Quality-Critical Envir...
 
Closing the Gap Between Risk and Requirements
Closing the Gap Between Risk and RequirementsClosing the Gap Between Risk and Requirements
Closing the Gap Between Risk and Requirements
 
Traceability Trends in Medical Device Development
Traceability Trends in Medical Device DevelopmentTraceability Trends in Medical Device Development
Traceability Trends in Medical Device Development
 
FMEA RCA Risk Management webinar
FMEA RCA Risk Management webinarFMEA RCA Risk Management webinar
FMEA RCA Risk Management webinar
 
Seapine driverless car safety infographic
Seapine driverless car safety infographicSeapine driverless car safety infographic
Seapine driverless car safety infographic
 
Seapine Scrum Reference Card
Seapine Scrum Reference CardSeapine Scrum Reference Card
Seapine Scrum Reference Card
 
The Road to Better Traceability
The Road to Better TraceabilityThe Road to Better Traceability
The Road to Better Traceability
 
2013 State of medical device webinar
2013 State of medical device webinar2013 State of medical device webinar
2013 State of medical device webinar
 
Beyond FDA Compliance Webinar: 5 Hidden Benefits of Your Traceability Matrix
Beyond FDA Compliance Webinar: 5 Hidden Benefits of Your Traceability MatrixBeyond FDA Compliance Webinar: 5 Hidden Benefits of Your Traceability Matrix
Beyond FDA Compliance Webinar: 5 Hidden Benefits of Your Traceability Matrix
 
Sw qual joint webinar deck (5)
Sw qual joint webinar deck (5)Sw qual joint webinar deck (5)
Sw qual joint webinar deck (5)
 
Pragmatic Device Risk Management
Pragmatic Device Risk Management Pragmatic Device Risk Management
Pragmatic Device Risk Management
 
Use the Windshield, Not the Mirror Predictive Metrics that Drive Successful ...
 Use the Windshield, Not the Mirror Predictive Metrics that Drive Successful ... Use the Windshield, Not the Mirror Predictive Metrics that Drive Successful ...
Use the Windshield, Not the Mirror Predictive Metrics that Drive Successful ...
 
Leveraging Reusability and Traceability in Medical Device Development
Leveraging Reusability and Traceability in Medical Device DevelopmentLeveraging Reusability and Traceability in Medical Device Development
Leveraging Reusability and Traceability in Medical Device Development
 
Webinar - Maximizing Requirements Value Throughout the Product Lifecycle
Webinar - Maximizing Requirements Value Throughout the Product Lifecycle Webinar - Maximizing Requirements Value Throughout the Product Lifecycle
Webinar - Maximizing Requirements Value Throughout the Product Lifecycle
 
Medical Device Development - Automating Traceability and Documentation
Medical Device Development - Automating Traceability and DocumentationMedical Device Development - Automating Traceability and Documentation
Medical Device Development - Automating Traceability and Documentation
 
FDA Expectations for Traceability in Device & Diagnostic Design
FDA Expectations for Traceability in Device & Diagnostic DesignFDA Expectations for Traceability in Device & Diagnostic Design
FDA Expectations for Traceability in Device & Diagnostic Design
 
Take the Pain (and Weekends) Out of Test Case Management
Take the Pain (and Weekends) Out of Test Case ManagementTake the Pain (and Weekends) Out of Test Case Management
Take the Pain (and Weekends) Out of Test Case Management
 
Understanding the Business Case for Agile
Understanding the Business Case for AgileUnderstanding the Business Case for Agile
Understanding the Business Case for Agile
 
When Requirements Change
When Requirements ChangeWhen Requirements Change
When Requirements Change
 
Agile at Seapine (University of Cincinnati 2011)
Agile at Seapine (University of Cincinnati 2011)Agile at Seapine (University of Cincinnati 2011)
Agile at Seapine (University of Cincinnati 2011)
 

Recently uploaded

Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Peter Udo Diehl
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 

Recently uploaded (20)

IESVE for Early Stage Design and Planning
IESVE for Early Stage Design and PlanningIESVE for Early Stage Design and Planning
IESVE for Early Stage Design and Planning
 
Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...Mission to Decommission: Importance of Decommissioning Products to Increase E...
Mission to Decommission: Importance of Decommissioning Products to Increase E...
 
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo DiehlFuture Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
Future Visions: Predictions to Guide and Time Tech Innovation, Peter Udo Diehl
 
Speed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in MinutesSpeed Wins: From Kafka to APIs in Minutes
Speed Wins: From Kafka to APIs in Minutes
 
Introduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG EvaluationIntroduction to Open Source RAG and RAG Evaluation
Introduction to Open Source RAG and RAG Evaluation
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 
What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024What's New in Teams Calling, Meetings and Devices April 2024
What's New in Teams Calling, Meetings and Devices April 2024
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1UiPath Test Automation using UiPath Test Suite series, part 1
UiPath Test Automation using UiPath Test Suite series, part 1
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024IoT Analytics Company Presentation May 2024
IoT Analytics Company Presentation May 2024
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptxWSO2CONMay2024OpenSourceConferenceDebrief.pptx
WSO2CONMay2024OpenSourceConferenceDebrief.pptx
 

Test-Driven Development Reference Card

  • 1. What is Test-Driven Development (TDD)? TDD is the practice of writing a unit test before writing any code. This can be done relatively quickly, with the developer writing the test, then writing the code, and then running the test, all in small increments. TDD ensures the code is consistently refactored for a better design. However, TDD isn’t a replacement for regression suites, design specifications, QA, or code reviews. TDD = TFD (Test Fi rst Desi gn) + Refa cto r Contrary to popular opinion, Agile is not cowboy coding. If there’s no BDUF (Big Design Up Front), how do you ensure your coding process has some structure? TDD is one answer. What’s the goal of TDD? To write “clean code that works”. (According to Ron Jeffries, http://xprogramming.com/index.php.) What are the benefits of TDD? • Better code design • Earlier defect detection • Fewer defects in production releases • Significant drop in defect density • Disciplined, quality-focused coding practices e rit hat W t t e s fa i l s t Cha n c od g e e y V e r i fs t s e a l l ta s s p
  • 2. TDD Activities Step 1 2 Working with Legacy Code You can use TDD with your existing legacy code, but it can be overwhelming if the code wasn’t designed to be testable. Following are a few tips to help you get started: Activity Write a test to verify new or changed functionality. 1. Refactor the code you are changing so it is testable. Run all tests and verify the new one fails (since it hasn’t been implemented yet). 2. Look for “code smells”—symptoms in the source code that could indicate a deeper problem. 3. Don’t worry about code coverage in old code. 3 Change the code just enough so that all tests pass. Your goal at this stage is to pass the test, so the code may not be elegant. 4 Refactor as needed to clean up the code. Verify all tests still pass after the refactor. 5 Repeat the process for the next change. Writing a Good Unit Test Sample Unit Test: Constructor Default Values Good unit tests are the backbone of successful TDD. Keep the following in mind as you write unit tests: • Each unit test should be independent. • Each unit test should test one aspect or behavior and document the expected behavior. • Each unit test should not verify too much functionality. • Each unit test should not be dependent on interface. Cincinnati • London • Munich • Melbourne • Johannesburg To learn more, check out Working Effectively with Legacy Code, by Michael Feathers. www.seapine.com © 2014, Seapine Software, Inc. All rights reserved. /* The purpose of this test is to verify the default values branchid should be INVALID_RECORD_ID, recursive should be set to true */ TEST(SCMWorkingDirTestSuite_Constructor_DefaultValues) { CSCMWorkingDirListObj workDir; CHECK_EQUAL(INVALID_RECORD_ID, workDir.GetBranchID()); CHECK_EQUAL(static_cast<Boolean>(TRUE), workDir.GetRecursive()); };