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

Agile methods series (xp)
Agile methods series (xp)Agile methods series (xp)
Agile methods series (xp)
XPDays
 
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)
Eddie Kenny
 
Pinpointing and Exploiting Specific Performance Bottlenecks
Pinpointing and Exploiting Specific Performance BottlenecksPinpointing and Exploiting Specific Performance Bottlenecks
Pinpointing and Exploiting Specific Performance Bottlenecks
Scott Barber
 
Test Driven Development Powered by LEGO
Test Driven Development Powered by LEGOTest Driven Development Powered by LEGO
Test Driven Development Powered by LEGO
Agile Montréal
 
Testing and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons LearnedTesting and DevOps Culture: Lessons Learned
Testing and DevOps Culture: Lessons LearnedLB Denker
 
Thuy_Tran_Ngoc_-_SD0585
Thuy_Tran_Ngoc_-_SD0585Thuy_Tran_Ngoc_-_SD0585
Thuy_Tran_Ngoc_-_SD0585tester Tran
 
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
Prafulla Girgaonkar
 
How to test a Mainframe Application
How to test a Mainframe ApplicationHow to test a Mainframe Application
How to test a Mainframe Application
Michael Erichsen
 
Introducing Agile Methodologies
Introducing Agile MethodologiesIntroducing Agile Methodologies
Introducing Agile Methodologies
Stfalcon Meetups
 
SbE - Requirements in an agile process
SbE - Requirements in an agile processSbE - Requirements in an agile process
SbE - Requirements in an agile processChris Schotanus
 
Introduction to Agile Software Development Process
Introduction to Agile Software Development ProcessIntroduction to Agile Software Development Process
Introduction to Agile Software Development Process
Software Park Thailand
 
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
Eduardo Ferro Aldama
 
devops, microservices, and platforms, oh my!
devops, microservices, and platforms, oh my!devops, microservices, and platforms, oh my!
devops, microservices, and platforms, oh my!
Andrew Shafer
 
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!
VMware Tanzu
 
Agile Testing - What is it?
Agile Testing - What is it?Agile Testing - What is it?
Agile Testing - What is it?
Intelliware Development Inc.
 
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
DevOps for Enterprise Systems
 
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...
apidays
 
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
michael.labriola
 
DevOps Game at SGZA
DevOps Game at SGZADevOps Game at SGZA
DevOps Game at SGZA
Dana Pylayeva
 

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

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
Product School
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
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...
Product School
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
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...
Jeffrey Haguewood
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
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
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 

Recently uploaded (20)

The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
From Daily Decisions to Bottom Line: Connecting Product Work to Revenue by VP...
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
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...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
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...
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
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
 
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 

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