SlideShare a Scribd company logo
14 July 2011 © Agile Institute 2011 1 Café TDD? Sure, but What About My Legacy Code? Rob Myers for Test Driven Developers Bay Area 14 Jul 2011
What is “Legacy Code”? 14 July 2011 © Agile Institute 2011 2
14 July 2011 © Agile Institute 2011 3 “Code we’re afraid to change.” -- James Shore “Code without tests.” -- Michael Feathers
14 July 2011 © Agile Institute 2011 4
Adding Tests Is Difficult 14 July 2011 © Agile Institute 2011 5 Circumstantial coupling: "I can’t test this without instantiating half the system!" Peculiar encapsulation:  “I wish I could just test that private method!” Duplication:"I'll have to test this on all the subclasses!" Poor cohesion: "This MasterControlClass does everything, so the test will be enormous and complex!"
A Conundrum 14 July 2011 © Agile Institute 2011 6 We add tests to refactor safely. We have to refactor to add safe tests.
14 July 2011 © Agile Institute 2011 7 What could possibly go wrong?!
Choose Your Battles Test the code you need to change now (unless it is very difficult) Test the code that changes most often (even if it is difficult) Test the code that haunts your nightmares! 14 July 2011 © Agile Institute 2011 8
Write “Pinning” Tests We don’t add or change behavior. We’re not bug-hunting. We aim for coverage. We must see GREEN. 14 July 2011 © Agile Institute 2011 9
Technique: “The Three Questions” What behavior needs test coverage? What’s preventing us from writing a test? What can we do about that? 14 July 2011 © Agile Institute 2011 10
Technique:Separate Behavior from Initialization It’s easier to test behavior when not coupled to initialization code. Use ‘Extract Method’ to preserve existing interfaces. 14 July 2011 © Agile Institute 2011 11
Before 14 July 2011 © Agile Institute 2011 12 public void OpenOrderReport( OutputGadget output, string accountNumber) {     Account account = LunExData.QueryAccount(accountNumber);     Order[] openOrders = LunExData.QueryOrders(             "open", accountNumber, DateTime.Now); foreach (Order order in openOrders) {         // ... output.Write("Order #" + order.Number);         // ...     } }
After ‘Extract Method’ 14 July 2011 © Agile Institute 2011 13 public void OpenOrderReport( OutputGadget output, string accountNumber) {     Account account = LunExData.QueryAccount(accountNumber);     Order[] openOrders = LunExData.QueryOrders(             "open", accountNumber, DateTime.Now); FormatOpenOrderReport(output, account, openOrders); } private void FormatOpenOrderReport( OutputGadget output,     Account account, Order[] openOrders) { foreach (Order order in openOrders) {         // ... output.Write("Order #" + order.Number);         // ...
Technique:Expose A Private Variable or Method Make a method public (at least accessible to tests) Wrap a variable in getter/setter methods. It may smell really bad. It will eventually be a useful addition to the interface, or will move to another object. 14 July 2011 © Agile Institute 2011 14
Before 14 July 2011 © Agile Institute 2011 15 private void FormatOpenOrderReport( OutputGadget output,     Account account, Order[] openOrders) { foreach (Order order in openOrders) {         // ... output.Write("Order #" + order.Number);         // ...     } }
After 14 July 2011 © Agile Institute 2011 16 public void FormatOpenOrderReport( OutputGadget output,     Account account, Order[] openOrders) { foreach (Order order in openOrders) {         // ... output.Write("Order #" + order.Number);         // ...     } }
Technique:Wrap, Then Mock Add a simple delegating Proxy to… Code we cannot change. Final (Java) or sealed (.NET) classes. Classes with no accessible constructors. Anything with a broad (mostly-unused) interface. Feathers’s “Adapt Parameter” is an example of this. 14 July 2011 © Agile Institute 2011 17
Delegating Proxy 14 July 2011 © Agile Institute 2011 18 ObjectUnderTest + MethodToTest() BrainlessProxy XYZZY + intFoo() + string Bar(int) + intFoo() + string Bar(int) + double Baz()
A New Production Class 14 July 2011 © Agile Institute 2011 19 public class BrainlessProxy {     private XYZZY realOne;     public BrainlessProxy(XYZZY theRealXYZZY) { this.realOne = theRealXYZZY;     }     public virtual intFoo() {         return realOne.Foo();     }     public virtual string Bar(int parameter) {         return realOne.Bar(parameter);     } }
Tough Problem (Simple Example) 14 July 2011 © Agile Institute 2011 20 public class TrafficLight {     public void SwitchLights() {         Color newColor;         if (currentColor.IsRed()) newColor = new Green();         else if (currentColor.IsGreen()) newColor = new Yellow();         else newColor = new Red(); currentColor.Flash();         Pause(3); currentColor.StopFlashing(); newColor.LightUp(); currentColor.Off(); currentColor = newColor;     }
Technique:Factory-Method Injection Extract a Factory Method for the dependency. Let the test create a “Testable” subclass of the Object Under Test. TestableFoo overrides the Factory Method and injects the mock. 14 July 2011 © Agile Institute 2011 21
Before ‘Extract Method’ 14 July 2011 © Agile Institute 2011 22 public void SwitchLights() {         Color newColor;         if (currentColor.IsRed()) newColor = new Green();         else if (currentColor.IsGreen()) newColor = new Yellow();         else newColor = new Red(); currentColor.Flash();         Pause(3); currentColor.StopFlashing(); newColor.LightUp(); currentColor.Off(); currentColor = newColor;     }
After ‘Extract Method’ part I 14 July 2011 © Agile Institute 2011 23 public void SwitchLights() {     Color newColor; newColor = NextColor(currentColor); currentColor.Flash();     Pause(3); currentColor.StopFlashing(); newColor.LightUp(); currentColor.Off(); currentColor = newColor; }
After ‘Extract Method’ Part II 14 July 2011 © Agile Institute 2011 24 private Color NextColor(Color currentColor) {     Color newColor;     if (currentColor.IsRed()) newColor = new Green();     else if (currentColor.IsGreen()) newColor = new Yellow();     else newColor = new Red();     return newColor; }
A Small Change 14 July 2011 © Agile Institute 2011 25 protected virtual Color NextColor(Color currentColor) {     Color newColor;     if (currentColor.IsRed()) newColor = new Green();     else if (currentColor.IsGreen()) newColor = new Yellow();     else newColor = new Red();     return newColor; }
The Test, Part 1 14 July 2011 © Agile Institute 2011 26 public static MockColornewColor; [TestMethod] public void TrafficLightSwitchTurnsNextColorOn() { newColor = new MockColor(); TrafficLighttrafficLight = new TestableTrafficLight(); trafficLight.SwitchLights(); Assert.IsTrue(newColor.WasTurnedOn()); }
The Test, Part 2Override Just  the Factory Method 14 July 2011 © Agile Institute 2011 27 public class TestableTrafficLight : TrafficLight {     protected override Color NextColor(Color currentColor) {         return newColor;     } } public class MockColor : Color {     bool wasLit = false;     public override void LightUp() {         wasLit = true;     }     public bool WasTurnedOn() {         return wasLit;     } }
When to Use a Factory Method “I don’t know, but…” If creation of the dependency is buried deep within conditional code. If the Factory Method is (or can be) used in multiple places. If Dependency Injection seems worse (e.g. at a published API). 14 July 2011 © Agile Institute 2011 28
14 July 2011 © Agile Institute 2011 29
14 July 2011 © Agile Institute 2011 30
14 July 2011 © Agile Institute 2011 31  Rob.Myers@agileInstitute.com http://PowersOfTwo.agileInstitute.com/

More Related Content

What's hot

Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
pleeps
 
Unit test-using-spock in Grails
Unit test-using-spock in GrailsUnit test-using-spock in Grails
Unit test-using-spock in Grails
NexThoughts Technologies
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
TO THE NEW | Technology
 
Appium TestNG Framework and Multi-Device Automation Execution
Appium TestNG Framework and Multi-Device Automation ExecutionAppium TestNG Framework and Multi-Device Automation Execution
Appium TestNG Framework and Multi-Device Automation Execution
pCloudy
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
Danairat Thanabodithammachari
 
Java performance
Java performanceJava performance
Java performance
Sergey D
 
xUnit Style Database Testing
xUnit Style Database TestingxUnit Style Database Testing
xUnit Style Database Testing
Chris Oldwood
 
Extending C# with Roslyn and Code Aware Libraries
Extending C# with Roslyn and Code Aware LibrariesExtending C# with Roslyn and Code Aware Libraries
Extending C# with Roslyn and Code Aware Libraries
Carlo Pescio
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good TestsTomek Kaczanowski
 
GMock framework
GMock frameworkGMock framework
GMock framework
corehard_by
 
Unit testing patterns for concurrent code
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent code
Dror Helper
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
Tomek Kaczanowski
 
JUnit Pioneer
JUnit PioneerJUnit Pioneer
JUnit Pioneer
Scott Leberknight
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
Dror Helper
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
Dror Helper
 
Testing logging in asp dot net core
Testing logging in asp dot net coreTesting logging in asp dot net core
Testing logging in asp dot net core
Rajesh Shirsagar
 
Server1
Server1Server1
Server1
FahriIrawan3
 
Decompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationDecompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 Presentation
James Hamilton
 
Algoritmos sujei
Algoritmos sujeiAlgoritmos sujei
Algoritmos sujei
gersonjack
 

What's hot (20)

Grails unit testing
Grails unit testingGrails unit testing
Grails unit testing
 
Unit test-using-spock in Grails
Unit test-using-spock in GrailsUnit test-using-spock in Grails
Unit test-using-spock in Grails
 
Grails Spock Testing
Grails Spock TestingGrails Spock Testing
Grails Spock Testing
 
Appium TestNG Framework and Multi-Device Automation Execution
Appium TestNG Framework and Multi-Device Automation ExecutionAppium TestNG Framework and Multi-Device Automation Execution
Appium TestNG Framework and Multi-Device Automation Execution
 
Java Programming - 03 java control flow
Java Programming - 03 java control flowJava Programming - 03 java control flow
Java Programming - 03 java control flow
 
Java performance
Java performanceJava performance
Java performance
 
xUnit Style Database Testing
xUnit Style Database TestingxUnit Style Database Testing
xUnit Style Database Testing
 
Extending C# with Roslyn and Code Aware Libraries
Extending C# with Roslyn and Code Aware LibrariesExtending C# with Roslyn and Code Aware Libraries
Extending C# with Roslyn and Code Aware Libraries
 
33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests33rd Degree 2013, Bad Tests, Good Tests
33rd Degree 2013, Bad Tests, Good Tests
 
GMock framework
GMock frameworkGMock framework
GMock framework
 
Unit testing patterns for concurrent code
Unit testing patterns for concurrent codeUnit testing patterns for concurrent code
Unit testing patterns for concurrent code
 
2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests2012 JDays Bad Tests Good Tests
2012 JDays Bad Tests Good Tests
 
JUnit Pioneer
JUnit PioneerJUnit Pioneer
JUnit Pioneer
 
Building unit tests correctly
Building unit tests correctlyBuilding unit tests correctly
Building unit tests correctly
 
Navigating the xDD Alphabet Soup
Navigating the xDD Alphabet SoupNavigating the xDD Alphabet Soup
Navigating the xDD Alphabet Soup
 
Testing logging in asp dot net core
Testing logging in asp dot net coreTesting logging in asp dot net core
Testing logging in asp dot net core
 
Server1
Server1Server1
Server1
 
Decompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 PresentationDecompiling Java - SCAM2009 Presentation
Decompiling Java - SCAM2009 Presentation
 
Algoritmos sujei
Algoritmos sujeiAlgoritmos sujei
Algoritmos sujei
 
Java programs
Java programsJava programs
Java programs
 

Viewers also liked

Baromètre e-commerce PowerBoutique - édition 2014
Baromètre e-commerce PowerBoutique - édition 2014Baromètre e-commerce PowerBoutique - édition 2014
Baromètre e-commerce PowerBoutique - édition 2014
PowerBoutique
 
L'activité e-commerce des TPE-PME - Edition 2012
L'activité e-commerce des TPE-PME - Edition 2012L'activité e-commerce des TPE-PME - Edition 2012
L'activité e-commerce des TPE-PME - Edition 2012
PowerBoutique
 
Enquête e-commerce PowerBoutique 2008
Enquête e-commerce PowerBoutique 2008Enquête e-commerce PowerBoutique 2008
Enquête e-commerce PowerBoutique 2008
PowerBoutique
 
Ποιος είμαι Γ2
Ποιος είμαι  Γ2Ποιος είμαι  Γ2
Ποιος είμαι Γ2
Βασιλική Καρβούνη
 
Η οικογένειά μου Β1
Η οικογένειά μου Β1Η οικογένειά μου Β1
Η οικογένειά μου Β1
Βασιλική Καρβούνη
 
Ε1 Ωρολόγιο πρόγραμμα
Ε1 Ωρολόγιο πρόγραμμαΕ1 Ωρολόγιο πρόγραμμα
Ε1 Ωρολόγιο πρόγραμμα
Βασιλική Καρβούνη
 
The Business Value of Test-Driven Development
The Business Value of Test-Driven DevelopmentThe Business Value of Test-Driven Development
The Business Value of Test-Driven Development
Rob Myers
 
Testistanbul 2016 - Formula 1, Continuous Integration, Continuous Delivery an...
Testistanbul 2016 - Formula 1, Continuous Integration, Continuous Delivery an...Testistanbul 2016 - Formula 1, Continuous Integration, Continuous Delivery an...
Testistanbul 2016 - Formula 1, Continuous Integration, Continuous Delivery an...
Turkish Testing Board
 
Testistanbul 2016 - Keynote: "Why Automated Verification Matters" by Kristian...
Testistanbul 2016 - Keynote: "Why Automated Verification Matters" by Kristian...Testistanbul 2016 - Keynote: "Why Automated Verification Matters" by Kristian...
Testistanbul 2016 - Keynote: "Why Automated Verification Matters" by Kristian...
Turkish Testing Board
 
Fastrack Digital Marketing Campaign Strategy by Jubaer
Fastrack Digital Marketing Campaign  Strategy by JubaerFastrack Digital Marketing Campaign  Strategy by Jubaer
Fastrack Digital Marketing Campaign Strategy by Jubaer
Abu Jubaer
 
Van droom tot werkelijkheid
Van droom tot werkelijkheidVan droom tot werkelijkheid
Van droom tot werkelijkheidArnaud Veere
 
FINAL SHEETS SEMINAR 21 MAART CHINA OUDEREN
FINAL SHEETS SEMINAR 21 MAART CHINA OUDERENFINAL SHEETS SEMINAR 21 MAART CHINA OUDEREN
FINAL SHEETS SEMINAR 21 MAART CHINA OUDERENArnaud Veere
 
China left behind children program vers maart 2016
China left behind children program vers maart 2016China left behind children program vers maart 2016
China left behind children program vers maart 2016Arnaud Veere
 

Viewers also liked (14)

Baromètre e-commerce PowerBoutique - édition 2014
Baromètre e-commerce PowerBoutique - édition 2014Baromètre e-commerce PowerBoutique - édition 2014
Baromètre e-commerce PowerBoutique - édition 2014
 
Kasner, Resume
Kasner, ResumeKasner, Resume
Kasner, Resume
 
L'activité e-commerce des TPE-PME - Edition 2012
L'activité e-commerce des TPE-PME - Edition 2012L'activité e-commerce des TPE-PME - Edition 2012
L'activité e-commerce des TPE-PME - Edition 2012
 
Enquête e-commerce PowerBoutique 2008
Enquête e-commerce PowerBoutique 2008Enquête e-commerce PowerBoutique 2008
Enquête e-commerce PowerBoutique 2008
 
Ποιος είμαι Γ2
Ποιος είμαι  Γ2Ποιος είμαι  Γ2
Ποιος είμαι Γ2
 
Η οικογένειά μου Β1
Η οικογένειά μου Β1Η οικογένειά μου Β1
Η οικογένειά μου Β1
 
Ε1 Ωρολόγιο πρόγραμμα
Ε1 Ωρολόγιο πρόγραμμαΕ1 Ωρολόγιο πρόγραμμα
Ε1 Ωρολόγιο πρόγραμμα
 
The Business Value of Test-Driven Development
The Business Value of Test-Driven DevelopmentThe Business Value of Test-Driven Development
The Business Value of Test-Driven Development
 
Testistanbul 2016 - Formula 1, Continuous Integration, Continuous Delivery an...
Testistanbul 2016 - Formula 1, Continuous Integration, Continuous Delivery an...Testistanbul 2016 - Formula 1, Continuous Integration, Continuous Delivery an...
Testistanbul 2016 - Formula 1, Continuous Integration, Continuous Delivery an...
 
Testistanbul 2016 - Keynote: "Why Automated Verification Matters" by Kristian...
Testistanbul 2016 - Keynote: "Why Automated Verification Matters" by Kristian...Testistanbul 2016 - Keynote: "Why Automated Verification Matters" by Kristian...
Testistanbul 2016 - Keynote: "Why Automated Verification Matters" by Kristian...
 
Fastrack Digital Marketing Campaign Strategy by Jubaer
Fastrack Digital Marketing Campaign  Strategy by JubaerFastrack Digital Marketing Campaign  Strategy by Jubaer
Fastrack Digital Marketing Campaign Strategy by Jubaer
 
Van droom tot werkelijkheid
Van droom tot werkelijkheidVan droom tot werkelijkheid
Van droom tot werkelijkheid
 
FINAL SHEETS SEMINAR 21 MAART CHINA OUDEREN
FINAL SHEETS SEMINAR 21 MAART CHINA OUDERENFINAL SHEETS SEMINAR 21 MAART CHINA OUDEREN
FINAL SHEETS SEMINAR 21 MAART CHINA OUDEREN
 
China left behind children program vers maart 2016
China left behind children program vers maart 2016China left behind children program vers maart 2016
China left behind children program vers maart 2016
 

Similar to TDD? Sure, but What About My Legacy Code?

Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
Марія Русин
 
Essential Test-Driven Development
Essential Test-Driven DevelopmentEssential Test-Driven Development
Essential Test-Driven Development
TechWell
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in Yii
IlPeach
 
Agile mobile
Agile mobileAgile mobile
Agile mobile
Godfrey Nolan
 
JUnit 5
JUnit 5JUnit 5
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockRobot Media
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
ciklum_ods
 
SOLID
SOLIDSOLID
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
Leonid Maslov
 
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityPHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
Giorgio Sironi
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
Jose Manuel Pereira Garcia
 
Java 8
Java 8Java 8
Testing with VS2010 - A Bugs Life
Testing with VS2010 - A Bugs LifeTesting with VS2010 - A Bugs Life
Testing with VS2010 - A Bugs Life
Peter Gfader
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
Andres Almiray
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyJames Williams
 
No SQL Unit - Devoxx 2012
No SQL Unit - Devoxx 2012No SQL Unit - Devoxx 2012
No SQL Unit - Devoxx 2012
Alex Soto
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good Tests
Tomek Kaczanowski
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
Tomek Kaczanowski
 
7 stages of unit testing
7 stages of unit testing7 stages of unit testing
7 stages of unit testing
Jorge Ortiz
 
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonUnit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonbeITconference
 

Similar to TDD? Sure, but What About My Legacy Code? (20)

Junit and testNG
Junit and testNGJunit and testNG
Junit and testNG
 
Essential Test-Driven Development
Essential Test-Driven DevelopmentEssential Test-Driven Development
Essential Test-Driven Development
 
PHP Unit Testing in Yii
PHP Unit Testing in YiiPHP Unit Testing in Yii
PHP Unit Testing in Yii
 
Agile mobile
Agile mobileAgile mobile
Agile mobile
 
JUnit 5
JUnit 5JUnit 5
JUnit 5
 
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMockUnit testing in iOS featuring OCUnit, GHUnit & OCMock
Unit testing in iOS featuring OCUnit, GHUnit & OCMock
 
Bring the fun back to java
Bring the fun back to javaBring the fun back to java
Bring the fun back to java
 
SOLID
SOLIDSOLID
SOLID
 
2. Design patterns. part #2
2. Design patterns. part #22. Design patterns. part #2
2. Design patterns. part #2
 
PHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testabilityPHP Barcelona 2010 - Architecture and testability
PHP Barcelona 2010 - Architecture and testability
 
From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)From Legacy to Hexagonal (An Unexpected Android Journey)
From Legacy to Hexagonal (An Unexpected Android Journey)
 
Java 8
Java 8Java 8
Java 8
 
Testing with VS2010 - A Bugs Life
Testing with VS2010 - A Bugs LifeTesting with VS2010 - A Bugs Life
Testing with VS2010 - A Bugs Life
 
Javaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 GroovytestingJavaone2008 Bof 5101 Groovytesting
Javaone2008 Bof 5101 Groovytesting
 
Boosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with GroovyBoosting Your Testing Productivity with Groovy
Boosting Your Testing Productivity with Groovy
 
No SQL Unit - Devoxx 2012
No SQL Unit - Devoxx 2012No SQL Unit - Devoxx 2012
No SQL Unit - Devoxx 2012
 
Confitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good TestsConfitura 2012 Bad Tests, Good Tests
Confitura 2012 Bad Tests, Good Tests
 
GeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good TestsGeeCON 2012 Bad Tests, Good Tests
GeeCON 2012 Bad Tests, Good Tests
 
7 stages of unit testing
7 stages of unit testing7 stages of unit testing
7 stages of unit testing
 
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, MelonUnit & Automation Testing in Android - Stanislav Gatsev, Melon
Unit & Automation Testing in Android - Stanislav Gatsev, Melon
 

More from Rob Myers

The Business Value of Agile Engineering Practices
The Business Value of Agile Engineering PracticesThe Business Value of Agile Engineering Practices
The Business Value of Agile Engineering Practices
Rob Myers
 
Roots of Agility - Better Software Agile Dev Practices East 2014 Keynote
Roots of Agility - Better Software Agile Dev Practices East 2014 KeynoteRoots of Agility - Better Software Agile Dev Practices East 2014 Keynote
Roots of Agility - Better Software Agile Dev Practices East 2014 Keynote
Rob Myers
 
Assessing the business value of Agile Engineering Practices
Assessing the business value of Agile Engineering PracticesAssessing the business value of Agile Engineering Practices
Assessing the business value of Agile Engineering PracticesRob Myers
 
The Business Value of Agile Engineering Practices
The Business Value of Agile Engineering PracticesThe Business Value of Agile Engineering Practices
The Business Value of Agile Engineering Practices
Rob Myers
 
Unit-Testing Your Legacy JavaScript
Unit-Testing Your Legacy JavaScriptUnit-Testing Your Legacy JavaScript
Unit-Testing Your Legacy JavaScriptRob Myers
 
Mock Objects from Concept to Code
Mock Objects from Concept to CodeMock Objects from Concept to Code
Mock Objects from Concept to CodeRob Myers
 
Technical Debt
Technical DebtTechnical Debt
Technical Debt
Rob Myers
 
Successful Teams are TDD Teams
Successful Teams are TDD TeamsSuccessful Teams are TDD Teams
Successful Teams are TDD TeamsRob Myers
 
Test-Driven Development Overview
Test-Driven Development OverviewTest-Driven Development Overview
Test-Driven Development Overview
Rob Myers
 
Metrics In An Agile World
Metrics In An Agile WorldMetrics In An Agile World
Metrics In An Agile World
Rob Myers
 
The Value of Refactoring on an Agile Team
The Value of Refactoring on an Agile TeamThe Value of Refactoring on an Agile Team
The Value of Refactoring on an Agile Team
Rob Myers
 
Successful Teams are Test-Driven Teams
Successful Teams are Test-Driven TeamsSuccessful Teams are Test-Driven Teams
Successful Teams are Test-Driven Teams
Rob Myers
 
Agile Testing: Solving the Agilist\'s Dilemma
Agile Testing: Solving the Agilist\'s DilemmaAgile Testing: Solving the Agilist\'s Dilemma
Agile Testing: Solving the Agilist\'s Dilemma
Rob Myers
 

More from Rob Myers (13)

The Business Value of Agile Engineering Practices
The Business Value of Agile Engineering PracticesThe Business Value of Agile Engineering Practices
The Business Value of Agile Engineering Practices
 
Roots of Agility - Better Software Agile Dev Practices East 2014 Keynote
Roots of Agility - Better Software Agile Dev Practices East 2014 KeynoteRoots of Agility - Better Software Agile Dev Practices East 2014 Keynote
Roots of Agility - Better Software Agile Dev Practices East 2014 Keynote
 
Assessing the business value of Agile Engineering Practices
Assessing the business value of Agile Engineering PracticesAssessing the business value of Agile Engineering Practices
Assessing the business value of Agile Engineering Practices
 
The Business Value of Agile Engineering Practices
The Business Value of Agile Engineering PracticesThe Business Value of Agile Engineering Practices
The Business Value of Agile Engineering Practices
 
Unit-Testing Your Legacy JavaScript
Unit-Testing Your Legacy JavaScriptUnit-Testing Your Legacy JavaScript
Unit-Testing Your Legacy JavaScript
 
Mock Objects from Concept to Code
Mock Objects from Concept to CodeMock Objects from Concept to Code
Mock Objects from Concept to Code
 
Technical Debt
Technical DebtTechnical Debt
Technical Debt
 
Successful Teams are TDD Teams
Successful Teams are TDD TeamsSuccessful Teams are TDD Teams
Successful Teams are TDD Teams
 
Test-Driven Development Overview
Test-Driven Development OverviewTest-Driven Development Overview
Test-Driven Development Overview
 
Metrics In An Agile World
Metrics In An Agile WorldMetrics In An Agile World
Metrics In An Agile World
 
The Value of Refactoring on an Agile Team
The Value of Refactoring on an Agile TeamThe Value of Refactoring on an Agile Team
The Value of Refactoring on an Agile Team
 
Successful Teams are Test-Driven Teams
Successful Teams are Test-Driven TeamsSuccessful Teams are Test-Driven Teams
Successful Teams are Test-Driven Teams
 
Agile Testing: Solving the Agilist\'s Dilemma
Agile Testing: Solving the Agilist\'s DilemmaAgile Testing: Solving the Agilist\'s Dilemma
Agile Testing: Solving the Agilist\'s Dilemma
 

Recently uploaded

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
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
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
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
Elena Simperl
 
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
 
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
 
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
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
DianaGray10
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Ramesh Iyer
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
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
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
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
 
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
Tobias Schneck
 
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
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
Prayukth K V
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.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
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 

Recently uploaded (20)

Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
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
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
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
 
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...
 
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...
 
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
 
UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3UiPath Test Automation using UiPath Test Suite series, part 3
UiPath Test Automation using UiPath Test Suite series, part 3
 
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
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 -...
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
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...
 
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
 
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
 
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 previewState of ICS and IoT Cyber Threat Landscape Report 2024 preview
State of ICS and IoT Cyber Threat Landscape Report 2024 preview
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.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
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 

TDD? Sure, but What About My Legacy Code?

  • 1. 14 July 2011 © Agile Institute 2011 1 Café TDD? Sure, but What About My Legacy Code? Rob Myers for Test Driven Developers Bay Area 14 Jul 2011
  • 2. What is “Legacy Code”? 14 July 2011 © Agile Institute 2011 2
  • 3. 14 July 2011 © Agile Institute 2011 3 “Code we’re afraid to change.” -- James Shore “Code without tests.” -- Michael Feathers
  • 4. 14 July 2011 © Agile Institute 2011 4
  • 5. Adding Tests Is Difficult 14 July 2011 © Agile Institute 2011 5 Circumstantial coupling: "I can’t test this without instantiating half the system!" Peculiar encapsulation: “I wish I could just test that private method!” Duplication:"I'll have to test this on all the subclasses!" Poor cohesion: "This MasterControlClass does everything, so the test will be enormous and complex!"
  • 6. A Conundrum 14 July 2011 © Agile Institute 2011 6 We add tests to refactor safely. We have to refactor to add safe tests.
  • 7. 14 July 2011 © Agile Institute 2011 7 What could possibly go wrong?!
  • 8. Choose Your Battles Test the code you need to change now (unless it is very difficult) Test the code that changes most often (even if it is difficult) Test the code that haunts your nightmares! 14 July 2011 © Agile Institute 2011 8
  • 9. Write “Pinning” Tests We don’t add or change behavior. We’re not bug-hunting. We aim for coverage. We must see GREEN. 14 July 2011 © Agile Institute 2011 9
  • 10. Technique: “The Three Questions” What behavior needs test coverage? What’s preventing us from writing a test? What can we do about that? 14 July 2011 © Agile Institute 2011 10
  • 11. Technique:Separate Behavior from Initialization It’s easier to test behavior when not coupled to initialization code. Use ‘Extract Method’ to preserve existing interfaces. 14 July 2011 © Agile Institute 2011 11
  • 12. Before 14 July 2011 © Agile Institute 2011 12 public void OpenOrderReport( OutputGadget output, string accountNumber) { Account account = LunExData.QueryAccount(accountNumber); Order[] openOrders = LunExData.QueryOrders( "open", accountNumber, DateTime.Now); foreach (Order order in openOrders) { // ... output.Write("Order #" + order.Number); // ... } }
  • 13. After ‘Extract Method’ 14 July 2011 © Agile Institute 2011 13 public void OpenOrderReport( OutputGadget output, string accountNumber) { Account account = LunExData.QueryAccount(accountNumber); Order[] openOrders = LunExData.QueryOrders( "open", accountNumber, DateTime.Now); FormatOpenOrderReport(output, account, openOrders); } private void FormatOpenOrderReport( OutputGadget output, Account account, Order[] openOrders) { foreach (Order order in openOrders) { // ... output.Write("Order #" + order.Number); // ...
  • 14. Technique:Expose A Private Variable or Method Make a method public (at least accessible to tests) Wrap a variable in getter/setter methods. It may smell really bad. It will eventually be a useful addition to the interface, or will move to another object. 14 July 2011 © Agile Institute 2011 14
  • 15. Before 14 July 2011 © Agile Institute 2011 15 private void FormatOpenOrderReport( OutputGadget output, Account account, Order[] openOrders) { foreach (Order order in openOrders) { // ... output.Write("Order #" + order.Number); // ... } }
  • 16. After 14 July 2011 © Agile Institute 2011 16 public void FormatOpenOrderReport( OutputGadget output, Account account, Order[] openOrders) { foreach (Order order in openOrders) { // ... output.Write("Order #" + order.Number); // ... } }
  • 17. Technique:Wrap, Then Mock Add a simple delegating Proxy to… Code we cannot change. Final (Java) or sealed (.NET) classes. Classes with no accessible constructors. Anything with a broad (mostly-unused) interface. Feathers’s “Adapt Parameter” is an example of this. 14 July 2011 © Agile Institute 2011 17
  • 18. Delegating Proxy 14 July 2011 © Agile Institute 2011 18 ObjectUnderTest + MethodToTest() BrainlessProxy XYZZY + intFoo() + string Bar(int) + intFoo() + string Bar(int) + double Baz()
  • 19. A New Production Class 14 July 2011 © Agile Institute 2011 19 public class BrainlessProxy { private XYZZY realOne; public BrainlessProxy(XYZZY theRealXYZZY) { this.realOne = theRealXYZZY; } public virtual intFoo() { return realOne.Foo(); } public virtual string Bar(int parameter) { return realOne.Bar(parameter); } }
  • 20. Tough Problem (Simple Example) 14 July 2011 © Agile Institute 2011 20 public class TrafficLight { public void SwitchLights() { Color newColor; if (currentColor.IsRed()) newColor = new Green(); else if (currentColor.IsGreen()) newColor = new Yellow(); else newColor = new Red(); currentColor.Flash(); Pause(3); currentColor.StopFlashing(); newColor.LightUp(); currentColor.Off(); currentColor = newColor; }
  • 21. Technique:Factory-Method Injection Extract a Factory Method for the dependency. Let the test create a “Testable” subclass of the Object Under Test. TestableFoo overrides the Factory Method and injects the mock. 14 July 2011 © Agile Institute 2011 21
  • 22. Before ‘Extract Method’ 14 July 2011 © Agile Institute 2011 22 public void SwitchLights() { Color newColor; if (currentColor.IsRed()) newColor = new Green(); else if (currentColor.IsGreen()) newColor = new Yellow(); else newColor = new Red(); currentColor.Flash(); Pause(3); currentColor.StopFlashing(); newColor.LightUp(); currentColor.Off(); currentColor = newColor; }
  • 23. After ‘Extract Method’ part I 14 July 2011 © Agile Institute 2011 23 public void SwitchLights() { Color newColor; newColor = NextColor(currentColor); currentColor.Flash(); Pause(3); currentColor.StopFlashing(); newColor.LightUp(); currentColor.Off(); currentColor = newColor; }
  • 24. After ‘Extract Method’ Part II 14 July 2011 © Agile Institute 2011 24 private Color NextColor(Color currentColor) { Color newColor; if (currentColor.IsRed()) newColor = new Green(); else if (currentColor.IsGreen()) newColor = new Yellow(); else newColor = new Red(); return newColor; }
  • 25. A Small Change 14 July 2011 © Agile Institute 2011 25 protected virtual Color NextColor(Color currentColor) { Color newColor; if (currentColor.IsRed()) newColor = new Green(); else if (currentColor.IsGreen()) newColor = new Yellow(); else newColor = new Red(); return newColor; }
  • 26. The Test, Part 1 14 July 2011 © Agile Institute 2011 26 public static MockColornewColor; [TestMethod] public void TrafficLightSwitchTurnsNextColorOn() { newColor = new MockColor(); TrafficLighttrafficLight = new TestableTrafficLight(); trafficLight.SwitchLights(); Assert.IsTrue(newColor.WasTurnedOn()); }
  • 27. The Test, Part 2Override Just the Factory Method 14 July 2011 © Agile Institute 2011 27 public class TestableTrafficLight : TrafficLight { protected override Color NextColor(Color currentColor) { return newColor; } } public class MockColor : Color { bool wasLit = false; public override void LightUp() { wasLit = true; } public bool WasTurnedOn() { return wasLit; } }
  • 28. When to Use a Factory Method “I don’t know, but…” If creation of the dependency is buried deep within conditional code. If the Factory Method is (or can be) used in multiple places. If Dependency Injection seems worse (e.g. at a published API). 14 July 2011 © Agile Institute 2011 28
  • 29. 14 July 2011 © Agile Institute 2011 29
  • 30. 14 July 2011 © Agile Institute 2011 30
  • 31. 14 July 2011 © Agile Institute 2011 31 Rob.Myers@agileInstitute.com http://PowersOfTwo.agileInstitute.com/

Editor's Notes

  1. We want to convert the old tin can into <click>Why?
  2. It’s a compromise for quality’s sake.Unless you buy TypeMock ($$$). There is a down-side to TypeMock: If you can test without improving your design, will you *ever*…???
  3. Unplug the network!
  4. This isn’t TDD. But you won’t be able to proceed with TDD without these techniques.If we find a bug, record it: In a bug tracker, or as a story.Not isolation. These are not “unit tests” - These tests can cover as much behavior as possible (though they must still be deterministic and pretty fast). And they don’t have to be pretty!Pinning tests should pass.The test is trying to “pin” behavior so we can refactor further.
  5. What needs testing?
  6. Very easyLean on the compiler
  7. Production code!Can you test it?What good is it?
  8. Varying dependency creation ORDuplicated dependency creation OR both.
  9. Varying dependency creation ORDuplicated dependency creation OR both.
  10. Creation has been separated from use. JUST A LITTLE, BUT ENOUGH.
  11. What are we up to?
  12. Alex Chaffee and WilliamPietre
  13. Thank you!