SlideShare uma empresa Scribd logo
1 de 2
Baixar para ler offline
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());
};

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Semelhante a 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
 

Semelhante a 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
 

Mais de 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
 

Mais de 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)
 

Último

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

Último (20)

Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

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()); };