SlideShare uma empresa Scribd logo
1 de 20
What is TDD?
(answer: Test-Driven Development)


    … and why you should care

Clear Lines Consulting · clear-lines.com   11/8/2011 · 1
Once upon a Time…

    Design

                                   Implement

                                               Test




Clear Lines Consulting · clear-lines.com              11/8/2011 · 2
Stay buggy, my friends!




Clear Lines Consulting · clear-lines.com   11/8/2011 · 3
Start with the tests!




                                           If I needed to Add 1 + 1…
Clear Lines Consulting · clear-lines.com                       11/8/2011 · 4
If I needed to Add 1 + 1…
[Test]
public void When_Adding_One_Plus_One_Answer_Should_Be_Two()
{
  // Assert
  var expectedResult = 2;
  Assert.That(actualResult, Is.EqualTo(expectedResult));
}




                         … I would expect the answer to be 2
Clear Lines Consulting · clear-lines.com              11/8/2011 · 5
If I needed to Add 1 + 1…
[Test]
public void When_Adding_One_Plus_One_Answer_Should_Be_Two()
{
  // Act
  var actualResult = calculator.Add(1, 1);

    // Assert
    var expectedResult = 2;
    Assert.That(actualResult, Is.EqualTo(expectedResult));
}



                                           … I would need a Calculator
Clear Lines Consulting · clear-lines.com                        11/8/2011 · 6
If I needed to Add 1 + 1…
[Test]
public void When_Adding_One_Plus_One_Answer_Should_Be_Two()
{
  // Arrange
  var calculator = new Calculator();

    // Act
    var actualResult = calculator.Add(1, 1);

    // Assert
    var expectedResult = 2;
    Assert.That(actualResult, Is.EqualTo(expectedResult));
}

                                           … I would need some code
Clear Lines Consulting · clear-lines.com                     11/8/2011 · 7
If I needed to Add 1 + 1…




                                           … Does the code work?
Clear Lines Consulting · clear-lines.com                  11/8/2011 · 8
Testing frameworks




       MsTest

Clear Lines Consulting · clear-lines.com   11/8/2011 · 9
It’s not about Testing

»    It’s about writing Code that works, now
»    Imagine you had implemented the feature
»    … then implement it
»    Rinse & Repeat until you have no test to write




Clear Lines Consulting · clear-lines.com      11/8/2011 · 10
Why should you care?



Clear Lines Consulting · clear-lines.com   11/8/2011 · 11
The dreaded L word




                                           © www.dilbert.com
Clear Lines Consulting · clear-lines.com              11/8/2011 · 12
“To me, legacy code is
 simply code without
 tests.”
         Michael Feathers,
                   Working Effectively with Legacy Code

Clear Lines Consulting · clear-lines.com          11/8/2011 · 13
Did I break everything?




Clear Lines Consulting · clear-lines.com   11/8/2011 · 14
Tests: a Vise holding your code steady




Clear Lines Consulting · clear-lines.com   11/8/2011 · 15
A good test is

» Fast
» Focused
» Replicable
» Automated



Clear Lines Consulting · clear-lines.com   11/8/2011 · 16
Refactoring: improve the
       code structure, without
       changing its external
       behavior.

Clear Lines Consulting · clear-lines.com   11/8/2011 · 17
Red, Green, Refactor

                                   » Red: write a little test
                                     that doesn’t work
                                   » Green: make the test
                                     work quickly
                                   » Refactor: cleanup time!

Clear Lines Consulting · clear-lines.com                 11/8/2011 · 18
Test-Driven Development is a
    way of managing fear during
    programming.
                         Kent Beck,
                                           Test-Driven Development by Example




Clear Lines Consulting · clear-lines.com                                11/8/2011 · 19
The Cast
» Me: Mathias Brandewinder
       – mathias@clear-lines.com (clear-lines.com/blog)
» Frameworks/Tools
       – NUnit: www.nunit.org
       – xUnit: xunit.codeplex.com/
       – Resharper: www.jetbrains.com/resharper/
» Books
       – Kent Beck, “Test Driven Development by Example”
       – Michael Feathers, “Working Effectively with Legacy
         Code”
       – Roy Osherove, “The Art of Unit Testing”
Clear Lines Consulting · clear-lines.com               11/8/2011 · 20

Mais conteúdo relacionado

Semelhante a BizSpark SF Lightning Talk: "Refactoring and Test-Driven Development" by Mathias Brandewinder

Testing and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons LearnedTesting and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons Learned
LB Denker
 
Thuy_Tran_Ngoc_-_SD0585
Thuy_Tran_Ngoc_-_SD0585Thuy_Tran_Ngoc_-_SD0585
Thuy_Tran_Ngoc_-_SD0585
tester Tran
 
SbE - Requirements in an agile process
SbE - Requirements in an agile processSbE - Requirements in an agile process
SbE - Requirements in an agile process
Chris Schotanus
 

Semelhante a BizSpark SF Lightning Talk: "Refactoring and Test-Driven Development" by Mathias Brandewinder (20)

Agile methods series (xp)
Agile methods series (xp)Agile methods series (xp)
Agile methods series (xp)
 
Extreme delivery - Lean Agile Scotland 2019 (Abridged)
Extreme delivery - Lean Agile Scotland 2019 (Abridged)Extreme delivery - Lean Agile Scotland 2019 (Abridged)
Extreme delivery - Lean Agile Scotland 2019 (Abridged)
 
Pinpointing and Exploiting Specific Performance Bottlenecks
Pinpointing and Exploiting Specific Performance BottlenecksPinpointing and Exploiting Specific Performance Bottlenecks
Pinpointing and Exploiting Specific Performance Bottlenecks
 
Test Driven Development Powered by LEGO
Test Driven Development Powered by LEGOTest Driven Development Powered by LEGO
Test Driven Development Powered by LEGO
 
Testing and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons LearnedTesting and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons Learned
 
Thuy_Tran_Ngoc_-_SD0585
Thuy_Tran_Ngoc_-_SD0585Thuy_Tran_Ngoc_-_SD0585
Thuy_Tran_Ngoc_-_SD0585
 
E xtreme programming for etl and data analytics final
E xtreme programming for etl and data analytics finalE xtreme programming for etl and data analytics final
E xtreme programming for etl and data analytics final
 
How to test a Mainframe Application
How to test a Mainframe ApplicationHow to test a Mainframe Application
How to test a Mainframe Application
 
Introducing Agile Methodologies
Introducing Agile MethodologiesIntroducing Agile Methodologies
Introducing Agile Methodologies
 
SbE - Requirements in an agile process
SbE - Requirements in an agile processSbE - Requirements in an agile process
SbE - Requirements in an agile process
 
Introduction to Agile Software Development Process
Introduction to Agile Software Development ProcessIntroduction to Agile Software Development Process
Introduction to Agile Software Development Process
 
Bilbostack19 devops is not what you think
Bilbostack19 devops is not what you thinkBilbostack19 devops is not what you think
Bilbostack19 devops is not what you think
 
Cloud Foundry Summit 2015: Devops, microservices and platforms, oh my!
Cloud Foundry Summit 2015: Devops, microservices and platforms, oh my!Cloud Foundry Summit 2015: Devops, microservices and platforms, oh my!
Cloud Foundry Summit 2015: Devops, microservices and platforms, oh my!
 
devops, microservices, and platforms, oh my!
devops, microservices, and platforms, oh my!devops, microservices, and platforms, oh my!
devops, microservices, and platforms, oh my!
 
Agile Testing - What is it?
Agile Testing - What is it?Agile Testing - What is it?
Agile Testing - What is it?
 
Agile Testing
Agile Testing  Agile Testing
Agile Testing
 
Lessons Learned from Large Scale Adoption of DevOps for IBM z Systems Software
Lessons Learned from Large Scale Adoption of DevOps for IBM z Systems SoftwareLessons Learned from Large Scale Adoption of DevOps for IBM z Systems Software
Lessons Learned from Large Scale Adoption of DevOps for IBM z Systems Software
 
apidays LIVE New York - Navigating the Sea of Javascript Tools to Discover Sc...
apidays LIVE New York - Navigating the Sea of Javascript Tools to Discover Sc...apidays LIVE New York - Navigating the Sea of Javascript Tools to Discover Sc...
apidays LIVE New York - Navigating the Sea of Javascript Tools to Discover Sc...
 
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in FlexassertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
assertYourself - Breaking the Theories and Assumptions of Unit Testing in Flex
 
DevOps Game at SGZA
DevOps Game at SGZADevOps Game at SGZA
DevOps Game at SGZA
 

Último

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Último (20)

FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
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
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
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 ...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
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
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
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
 
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
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
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
 
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
 
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
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 

BizSpark SF Lightning Talk: "Refactoring and Test-Driven Development" by Mathias Brandewinder

  • 1. What is TDD? (answer: Test-Driven Development) … and why you should care Clear Lines Consulting · clear-lines.com 11/8/2011 · 1
  • 2. Once upon a Time… Design Implement Test Clear Lines Consulting · clear-lines.com 11/8/2011 · 2
  • 3. Stay buggy, my friends! Clear Lines Consulting · clear-lines.com 11/8/2011 · 3
  • 4. Start with the tests! If I needed to Add 1 + 1… Clear Lines Consulting · clear-lines.com 11/8/2011 · 4
  • 5. If I needed to Add 1 + 1… [Test] public void When_Adding_One_Plus_One_Answer_Should_Be_Two() { // Assert var expectedResult = 2; Assert.That(actualResult, Is.EqualTo(expectedResult)); } … I would expect the answer to be 2 Clear Lines Consulting · clear-lines.com 11/8/2011 · 5
  • 6. If I needed to Add 1 + 1… [Test] public void When_Adding_One_Plus_One_Answer_Should_Be_Two() { // Act var actualResult = calculator.Add(1, 1); // Assert var expectedResult = 2; Assert.That(actualResult, Is.EqualTo(expectedResult)); } … I would need a Calculator Clear Lines Consulting · clear-lines.com 11/8/2011 · 6
  • 7. If I needed to Add 1 + 1… [Test] public void When_Adding_One_Plus_One_Answer_Should_Be_Two() { // Arrange var calculator = new Calculator(); // Act var actualResult = calculator.Add(1, 1); // Assert var expectedResult = 2; Assert.That(actualResult, Is.EqualTo(expectedResult)); } … I would need some code Clear Lines Consulting · clear-lines.com 11/8/2011 · 7
  • 8. If I needed to Add 1 + 1… … Does the code work? Clear Lines Consulting · clear-lines.com 11/8/2011 · 8
  • 9. Testing frameworks MsTest Clear Lines Consulting · clear-lines.com 11/8/2011 · 9
  • 10. It’s not about Testing » It’s about writing Code that works, now » Imagine you had implemented the feature » … then implement it » Rinse & Repeat until you have no test to write Clear Lines Consulting · clear-lines.com 11/8/2011 · 10
  • 11. Why should you care? Clear Lines Consulting · clear-lines.com 11/8/2011 · 11
  • 12. The dreaded L word © www.dilbert.com Clear Lines Consulting · clear-lines.com 11/8/2011 · 12
  • 13. “To me, legacy code is simply code without tests.” Michael Feathers, Working Effectively with Legacy Code Clear Lines Consulting · clear-lines.com 11/8/2011 · 13
  • 14. Did I break everything? Clear Lines Consulting · clear-lines.com 11/8/2011 · 14
  • 15. Tests: a Vise holding your code steady Clear Lines Consulting · clear-lines.com 11/8/2011 · 15
  • 16. A good test is » Fast » Focused » Replicable » Automated Clear Lines Consulting · clear-lines.com 11/8/2011 · 16
  • 17. Refactoring: improve the code structure, without changing its external behavior. Clear Lines Consulting · clear-lines.com 11/8/2011 · 17
  • 18. Red, Green, Refactor » Red: write a little test that doesn’t work » Green: make the test work quickly » Refactor: cleanup time! Clear Lines Consulting · clear-lines.com 11/8/2011 · 18
  • 19. Test-Driven Development is a way of managing fear during programming. Kent Beck, Test-Driven Development by Example Clear Lines Consulting · clear-lines.com 11/8/2011 · 19
  • 20. The Cast » Me: Mathias Brandewinder – mathias@clear-lines.com (clear-lines.com/blog) » Frameworks/Tools – NUnit: www.nunit.org – xUnit: xunit.codeplex.com/ – Resharper: www.jetbrains.com/resharper/ » Books – Kent Beck, “Test Driven Development by Example” – Michael Feathers, “Working Effectively with Legacy Code” – Roy Osherove, “The Art of Unit Testing” Clear Lines Consulting · clear-lines.com 11/8/2011 · 20