SlideShare a Scribd company logo
1 of 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

More Related Content

Similar to 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
 

Similar to 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
 
devops, microservices, and platforms, oh my!
devops, microservices, and platforms, oh my!devops, microservices, and platforms, oh my!
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!
Cloud Foundry Summit 2015: 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
 

Recently uploaded

Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
UXDXConf
 

Recently uploaded (20)

Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone KomSalesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
Salesforce Adoption – Metrics, Methods, and Motivation, Antone Kom
 
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...
 
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
SOQL 201 for Admins & Developers: Slice & Dice Your Org’s Data With Aggregate...
 
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
FDO for Camera, Sensor and Networking Device – Commercial Solutions from VinC...
 
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptxUnpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
Unpacking Value Delivery - Agile Oxford Meetup - May 2024.pptx
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
PLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. StartupsPLAI - Acceleration Program for Generative A.I. Startups
PLAI - Acceleration Program for Generative A.I. Startups
 
Strategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering TeamsStrategic AI Integration in Engineering Teams
Strategic AI Integration in Engineering Teams
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 
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
 
Google I/O Extended 2024 Warsaw
Google I/O Extended 2024 WarsawGoogle I/O Extended 2024 Warsaw
Google I/O Extended 2024 Warsaw
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
ECS 2024 Teams Premium - Pretty Secure
ECS 2024   Teams Premium - Pretty SecureECS 2024   Teams Premium - Pretty Secure
ECS 2024 Teams Premium - Pretty Secure
 
Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024Top 10 Symfony Development Companies 2024
Top 10 Symfony Development Companies 2024
 
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
Secure Zero Touch enabled Edge compute with Dell NativeEdge via FDO _ Brad at...
 
How we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdfHow we scaled to 80K users by doing nothing!.pdf
How we scaled to 80K users by doing nothing!.pdf
 
Oauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoftOauth 2.0 Introduction and Flows with MuleSoft
Oauth 2.0 Introduction and Flows with MuleSoft
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
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
 

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