SlideShare a Scribd company logo
1 of 30
Download to read offline
9/9/13	
  

As you enter the room…
1.  Take a 3x5 card or piece of paper, create two columns.
2.  Write these skills in the first column: TDD, Refactoring,
OO, Java (or C#), Eclipse (or IDEA or VisualStudio)
3.  For each skill, rate yourself from 0 (never heard of it) to
10 (invented it), and record in the second column.
4.  Find someone (a) whom you don’t usually work with; and
(b) who has somewhat complementary skill levels (with
them, your average is 4 to 6). Write down this person’s
name, but only if both a and b are true.
5.  Repeat step 4 until you have two names.
9 September 2013

© Agile Institute 2008-2013

1

…get comfortable.
1.  Choose someone from
your list to work with.
2.  Gather your belongings
and select a workstation
for you and your new
lab partner.
3.  Settle in at that
workstation.

9 September 2013

© Agile Institute 2008-2013

2

1	
  
9/9/13	
  

Café
Essential
Test-Driven
Development
Rob Myers

for
Agile Development Practices
East
12 November 2013

9 September 2013

© Agile Institute 2008-2013

3

© Agile Institute 2008-2013

4

Unit testing
is soooo
DEPRESSING

9 September 2013

2	
  
9/9/13	
  

TDD is fun,
and provides
much more than
just unit-tests!

9 September 2013

© Agile Institute 2008-2013

5

“The results of the case studies indicate
that the pre-release defect density of the
four products decreased between 40%
and 90% relative to similar projects that
did

not

use

the

TDD

practice.

Subjectively, the teams experienced a
15–35% increase in initial development
time after adopting TDD.”
http://research.microsoft.com/en-us/projects/esm/nagappan_tdd.pdf, Nagappan et al,
© Springer Science + Business Media, LLC 2008
9 September 2013

© Agile Institute 2008-2013

6

3	
  
9/9/13	
  

TDD Demo

9 September 2013

© Agile Institute 2008-2013

7

No Magic
import org.junit.*;

public class FooTests {
@Test
public void fooBarIsBaz() {
Foo foo = new Foo();
Assert.assertEquals("Baz", foo.bar());
}
}

9 September 2013

© Agile Institute 2008-2013

8

4	
  
9/9/13	
  

Requirements & Conventions
import org.junit.*;

public class FooTests {
@Test
public void fooBarIsBaz() {
Foo foo = new Foo();
Assert.assertEquals("Baz", foo.bar());
}
}
Expected

9 September 2013

Actual

© Agile Institute 2008-2013

9

Basic UML Class Diagrams
Bar

Foo
- int privateVariable

+ void AbstractMethod(
object parameter)

+ int PublicMethod()

Baz
- void PrivateMethod()

9 September 2013

© Agile Institute 2008-2013

10

5	
  
9/9/13	
  

Global Currency Money-Market
Account

9 September 2013

© Agile Institute 2008-2013

11

Global
ATM
Access
9 September 2013

© Agile Institute 2008-2013

12

6	
  
9/9/13	
  

Stories
•  As Rob the US account holder, I want to be able to
withdraw USD from a US ATM, but select which currency
holdings to withdraw from.
•  As Rob, traveling in Europe, I want to be able to withdraw
EUR from either my EUR holdings or my USD holdings. The
default should be the most beneficial to me at the time.
•  Shortly after the end of each month, I want to receive a
report of my holdings and balance. The total balance
should appear in the currency of my account address
(USD).
9 September 2013

© Agile Institute 2008-2013

13

Primary Objects

Currency
Account

Holding

9 September 2013

© Agile Institute 2008-2013

14

7	
  
9/9/13	
  

More Detail

Currency

Holding
value
currency
currencyConverter
convert value to
another currency

9 September 2013

CurrencyConverter

© Agile Institute 2008-2013

15

Start Simple
To Do
q When currencies are the same.
q When value is zero.

9 September 2013

© Agile Institute 2008-2013

16

8	
  
9/9/13	
  

Specification, and Interface
@Test
public void givesSameValueWhenSameCurrencyRequested() {
CurrencyConverter converter = new CurrencyConverter();
String sameCurrency = "USD";
double sameValue = 100.0000;
double converted = converter.convert(
sameValue, sameCurrency, sameCurrency);
Assert.assertEquals(sameValue, converted, 0.00004);
}

Will not compile. L
9 September 2013

© Agile Institute 2008-2013

17

“Thank You, But…”
public class CurrencyConverter {
public double convert(
double value, String from, String to) {
throw new RuntimeException(
"D'oh! convert() not YET implemented!");
}
}

9 September 2013

© Agile Institute 2008-2013

18

9	
  
9/9/13	
  

“…I Want to See it Fail Successfully”
public class CurrencyConverter {
public double convert(
double value, String from, String to) {
return 0.0;
}
}

9 September 2013

© Agile Institute 2008-2013

19

Technique: “Fake It”
public class CurrencyConverter {
public double convert(
double value, String from, String to) {
return 100.0;
}
}

9 September 2013

© Agile Institute 2008-2013

20

10	
  
9/9/13	
  

a. Refactor Away the Duplication
@Test
public void givesSameValueWhenSameCurrencyRequested() {
CurrencyConverter converter = new CurrencyConverter();
String sameCurrency = "USD";
double sameValue = 100.0000;
double converted = converter.convert(
sameValue, sameCurrency, sameCurrency);
Assert.assertEquals(sameValue, converted, 0.00004);
}

public double convert(
double value, String from, String to) {
return 100.0;
}
9 September 2013

© Agile Institute 2008-2013

21

b. Triangulate

9 September 2013

© Agile Institute 2008-2013

22

11	
  
9/9/13	
  

We don’t add
any behavior
without a
failing test…

Rodin’s The Thinker, photo by CJ on Wikipedia

9 September 2013

© Agile Institute 2008-2013

23

Technique: “Triangulation”
@Test
public void givesZeroWhenValueIsZero() {
CurrencyConverter converter = new CurrencyConverter();
double zero = 0.0000;
double converted = converter.convert(
zero, "USD", "EUR");
Assert.assertEquals(zero, converted, 0.00004);
}

9 September 2013

© Agile Institute 2008-2013

24

12	
  
9/9/13	
  

Still “Fake”?
public class CurrencyConverter {
public double convert(
double value, String from, String to) {
return value;
}
}

9 September 2013

© Agile Institute 2008-2013

25

Maintain the Tests
@Test
public void givesZeroWhenValueIsZero() {
CurrencyConverter converter = new CurrencyConverter();
// ...
}
@Test
public void givesSameValueWhenSameCurrencyRequested() {
CurrencyConverter converter = new CurrencyConverter();
// ...
}

9 September 2013

© Agile Institute 2008-2013

26

13	
  
9/9/13	
  

@Before Runs Before Each Test
private CurrencyConverter converter;
@Before
public void initialize() {
converter = new CurrencyConverter();
}
@Test
public
//
}
@Test
public
//
}

void givesZeroWhenValueIsZero() {
...

void givesSameValueWhenSameCurrencyRequested() {
...

9 September 2013

© Agile Institute 2008-2013

27

What is the Expected Answer?
@Test
public void convertsDollarsToEuros() {
double converted = converter.convert(
100.0000, "USD", "EUR");
Assert.assertEquals(???, converted, 0.00004);
}

9 September 2013

© Agile Institute 2008-2013

28

14	
  
9/9/13	
  

Let’s Invent a Scenario…
@Test
public void convertsDollarsToEuros() {
double converted = converter.convert(
100.0000, "USD", "EUR");
Assert.assertEquals(50.0000, converted, 0.00004);
}

9 September 2013

© Agile Institute 2008-2013

29

…“Fake It”…
public double convert(
double value, String from, String to) {
if (to.equals(from))
return value;
return value * 0.5000;
}

9 September 2013

© Agile Institute 2008-2013

30

15	
  
9/9/13	
  

…Refactor…
public double convert(
double value, String from, String to) {
if (to.Equals(from))
return value;
return value * conversionRate(from, to);
}
private double conversionRate(String from, String to) {
return 0.5000;
}

9 September 2013

© Agile Institute 2008-2013

31

…And Make a Note of It
To Do
ü When currencies are the same.
ü When value is zero.
q Fix the hard-coded conversionRate

9 September 2013

© Agile Institute 2008-2013

32

16	
  
9/9/13	
  

Well, What is It???

Where does it come from?

9 September 2013

© Agile Institute 2008-2013

33

Circumstantial Coupling?

CurrencyConverter

9 September 2013

© Agile Institute 2008-2013

34

17	
  
9/9/13	
  

Managing the Transaction
Account

CurrencyConverter

Holding
Holding
Holding
Holding

9 September 2013

ConversionRates

© Agile Institute 2008-2013

35

Another Object Emerges
To Do
ü When currencies are the same.
ü When value is zero.
q Fix hard-coded conversionRate().
q Write ConversionRates.
q Make a factory for ConversionRates
that uses the FOREX.com Web Service.
9 September 2013

© Agile Institute 2008-2013

36

18	
  
9/9/13	
  

New Test Class
import org.junit.Assert;
import org.junit.Test;
public class ConversionRatesTest {
@Test
public void storesAndRetrievesRates() {
ConversionRates rates = new ConversionRates();
String from = "USD";
String to = "EUR";
double rate = 0.7424;
rates.putRate(from, to, rate);
Assert.assertEquals(rate, rates.getRate(from, to),
0.0004);
}
}
9 September 2013

© Agile Institute 2008-2013

37

Fail
public class ConversionRates {
public void putRate(String from, String to, double rate) {
}
public double getRate(String from, String to) {
return 0;
}
}

9 September 2013

© Agile Institute 2008-2013

38

19	
  
9/9/13	
  

Technique: “Obvious Implementation”
import java.util.HashMap;
import java.util.Map;
public class ConversionRates {
private Map<String, Double> rates
= new HashMap<String, Double>();
public void putRate(String from, String to, double rate) {
rates.put(from + to, rate);
}
public double getRate(String from, String to) {
return rates.get(from + to);
}
}
9 September 2013

© Agile Institute 2008-2013

39

Isolate Behavior
public class ConversionRates {
private Map<String, Double> rates
= new HashMap<String, Double>();
public void putRate(String from, String to, double rate) {
rates.put(key(from, to), rate);
}
public double getRate(String from, String to) {
return rates.get(key(from, to));
}
private String key(String from, String to) {
return from + to;
}
}
9 September 2013

© Agile Institute 2008-2013

40

20	
  
9/9/13	
  

Next?
To Do
ü When currencies are the same.
ü When value is zero.
q Fix hard-coded conversionRate().
ü Write ConversionRates.
q Make a factory for ConversionRates
that uses the FOREX.com Web Service.
9 September 2013

© Agile Institute 2008-2013

41

Fix @Before Method
public class CurrencyConverterTests {
private CurrencyConverter converter;
@Before
public void initialize() {
ConversionRates rates = new ConversionRates();
rates.putRate("USD", "EUR", 0.5000);
converter = new CurrencyConverter(rates);
}
// ...

9 September 2013

© Agile Institute 2008-2013

42

21	
  
9/9/13	
  

Partially Refactored…
public class CurrencyConverter {
private ConversionRates rates;
public CurrencyConverter(ConversionRates rates) {
this.rates = rates;
}
private double conversionRate(String from, String to) {
return 0.5000;
}
// ...

9 September 2013

© Agile Institute 2008-2013

43

Replace the Hard-Coded Value
public class CurrencyConverter {
private ConversionRates rates;
public CurrencyConverter(ConversionRates rates) {
this.rates = rates;
}
private double conversionRate(String from, String to) {
return rates.getRate(from, to);
}
// ...

9 September 2013

© Agile Institute 2008-2013

44

22	
  
9/9/13	
  

What Remains?
To Do
ü When currencies are the same.
ü When value is zero.
ü Fix hard-coded conversionRate().
ü Write ConversionRates.
q Make a factory for ConversionRates
that uses the FOREX.com Web
Service.
9 September 2013

© Agile Institute 2008-2013

45

What is the Missing Piece?

ConversionRates rates =
ConversionRates.byAccountAnd???(
account,

9 September 2013

© Agile Institute 2008-2013

???);

46

23	
  
9/9/13	
  

Ask What If…?
To Do
q Make a byAccountAndDate() factory
for ConversionRates that uses the
FOREX.com Web Service.
q ConversionRates returns 1/rate if
inverse rate found.
q ConversionRates throws when rate
not found.
9 September 2013

© Agile Institute 2008-2013

47

Testing Exceptional Behavior
@Test(expected=RateNotFoundException.class)
public void throwsExceptionIfRateNotFoundII() {
ConversionRates rates = new ConversionRates();
String from = "BAR";
String to = "BAZ";
rates.getRate(from, to);
}

9 September 2013

© Agile Institute 2008-2013

48

24	
  
9/9/13	
  

A New Exception
public class RateNotFoundException extends RuntimeException {
}

9 September 2013

© Agile Institute 2008-2013

49

9 September 2013

© Agile Institute 2008-2013

50

25	
  
9/9/13	
  

Back in ConversionRates
public double getRate(String from, String to) {
if (!rates.containsKey(key(from, to)))
throw new RateNotFoundException();
return rates.get(key(from, to));
}

9 September 2013

© Agile Institute 2008-2013

1.  Write one unit test.

51

steps

2.  Build or add to the object under test
until everything compiles.

3.  Red:

Watch the test fail!

4.  Green:

Make all the tests pass by
changing the object under test.

5.  Clean:

Refactor mercilessly!

6.  Repeat.
9 September 2013

© Agile Institute 2008-2013

52

26	
  
9/9/13	
  

Runs all the tests.
Expresses every idea required.
Says everything once and only once.
Has no superfluous parts.

9 September 2013

© Agile Institute 2008-2013

53

Exercise A: Password-Strength Checker

In order to be an acceptable password,
a string must:
q Have a length greater than 7
characters.
q Contain at least one alphabetic
character.
q Contain at least one digit.
9 September 2013

© Agile Institute 2008-2013

54

27	
  
9/9/13	
  

1.  Write one unit test.

steps

2.  Build or add to the object under test
until everything compiles.

3.  Red:

Watch the test fail!

4.  Green:

Make all the tests pass by
changing the object under test.

5.  Clean:

Refactor mercilessly!

6.  Repeat.
9 September 2013

© Agile Institute 2008-2013

55

Iteration 2
•  Admins and regular users:
•  Admin passwords must also...
•  Be > 10 chars long
•  Contain a special character

•  People want to know all the reasons why their
password has failed.
•  Other stronger rules may apply later. ;-)
•  HINT: What is varying most frequently?

Be sure to take a break when you need one!
9 September 2013

© Agile Institute 2008-2013

56

28	
  
9/9/13	
  

1.  Write one unit test.

steps

2.  Build or add to the object under test
until everything compiles.

3.  Red:

Watch the test fail!

4.  Green:

Make all the tests pass by
changing the object under test.

5.  Clean:

Refactor mercilessly!

6.  Repeat.
9 September 2013

© Agile Institute 2008-2013

57

1.  _______________________________________

2.  _______________________________________

3.  _______________________________________

CLOSING

9 September 2013

© Agile Institute 2008-2013

58

29	
  
9/9/13	
  

9 September 2013

© Agile Institute 2008-2013

59

Rob.Myers@agileInstitute.com
http://PowersOfTwo.agileInstitute.com/
@agilecoach

9 September 2013

© Agile Institute 2008-2013

60

30	
  

More Related Content

Viewers also liked

Disciplined Agile Delivery: Extending Scrum to the Enterprise
Disciplined Agile Delivery: Extending Scrum to the EnterpriseDisciplined Agile Delivery: Extending Scrum to the Enterprise
Disciplined Agile Delivery: Extending Scrum to the EnterpriseTechWell
 
Exploratory Testing Explained
Exploratory Testing ExplainedExploratory Testing Explained
Exploratory Testing ExplainedTechWell
 
Embracing Uncertainty: A Most Difficult Leap of Faith
Embracing Uncertainty: A Most Difficult Leap of FaithEmbracing Uncertainty: A Most Difficult Leap of Faith
Embracing Uncertainty: A Most Difficult Leap of FaithTechWell
 
The Journey from Manager to Leader: Empowering Your Team
The Journey from Manager to Leader: Empowering Your TeamThe Journey from Manager to Leader: Empowering Your Team
The Journey from Manager to Leader: Empowering Your TeamTechWell
 
High-flying Cloud Testing Techniques
High-flying Cloud Testing TechniquesHigh-flying Cloud Testing Techniques
High-flying Cloud Testing TechniquesTechWell
 
Key Test Design Techniques
Key Test Design TechniquesKey Test Design Techniques
Key Test Design TechniquesTechWell
 
Right-sized Architecture: Integrity for Emerging Designs
Right-sized Architecture: Integrity for Emerging DesignsRight-sized Architecture: Integrity for Emerging Designs
Right-sized Architecture: Integrity for Emerging DesignsTechWell
 
Coaching and Leading Agility: A Discussion of Agile Tuning
Coaching and Leading Agility: A Discussion of Agile TuningCoaching and Leading Agility: A Discussion of Agile Tuning
Coaching and Leading Agility: A Discussion of Agile TuningTechWell
 
ADC-BSC EAST 2013 Keynote: Reading the Tea Leaves: Predicting a Project’s Future
ADC-BSC EAST 2013 Keynote: Reading the Tea Leaves: Predicting a Project’s FutureADC-BSC EAST 2013 Keynote: Reading the Tea Leaves: Predicting a Project’s Future
ADC-BSC EAST 2013 Keynote: Reading the Tea Leaves: Predicting a Project’s FutureTechWell
 
Critical Thinking for Software Testers
Critical Thinking for Software TestersCritical Thinking for Software Testers
Critical Thinking for Software TestersTechWell
 

Viewers also liked (10)

Disciplined Agile Delivery: Extending Scrum to the Enterprise
Disciplined Agile Delivery: Extending Scrum to the EnterpriseDisciplined Agile Delivery: Extending Scrum to the Enterprise
Disciplined Agile Delivery: Extending Scrum to the Enterprise
 
Exploratory Testing Explained
Exploratory Testing ExplainedExploratory Testing Explained
Exploratory Testing Explained
 
Embracing Uncertainty: A Most Difficult Leap of Faith
Embracing Uncertainty: A Most Difficult Leap of FaithEmbracing Uncertainty: A Most Difficult Leap of Faith
Embracing Uncertainty: A Most Difficult Leap of Faith
 
The Journey from Manager to Leader: Empowering Your Team
The Journey from Manager to Leader: Empowering Your TeamThe Journey from Manager to Leader: Empowering Your Team
The Journey from Manager to Leader: Empowering Your Team
 
High-flying Cloud Testing Techniques
High-flying Cloud Testing TechniquesHigh-flying Cloud Testing Techniques
High-flying Cloud Testing Techniques
 
Key Test Design Techniques
Key Test Design TechniquesKey Test Design Techniques
Key Test Design Techniques
 
Right-sized Architecture: Integrity for Emerging Designs
Right-sized Architecture: Integrity for Emerging DesignsRight-sized Architecture: Integrity for Emerging Designs
Right-sized Architecture: Integrity for Emerging Designs
 
Coaching and Leading Agility: A Discussion of Agile Tuning
Coaching and Leading Agility: A Discussion of Agile TuningCoaching and Leading Agility: A Discussion of Agile Tuning
Coaching and Leading Agility: A Discussion of Agile Tuning
 
ADC-BSC EAST 2013 Keynote: Reading the Tea Leaves: Predicting a Project’s Future
ADC-BSC EAST 2013 Keynote: Reading the Tea Leaves: Predicting a Project’s FutureADC-BSC EAST 2013 Keynote: Reading the Tea Leaves: Predicting a Project’s Future
ADC-BSC EAST 2013 Keynote: Reading the Tea Leaves: Predicting a Project’s Future
 
Critical Thinking for Software Testers
Critical Thinking for Software TestersCritical Thinking for Software Testers
Critical Thinking for Software Testers
 

Similar to Essential Test-Driven Development

Essential Test-Driven Development
Essential Test-Driven DevelopmentEssential Test-Driven Development
Essential Test-Driven DevelopmentTechWell
 
Dependency Injection @ AngularJS
Dependency Injection @ AngularJSDependency Injection @ AngularJS
Dependency Injection @ AngularJSRan Mizrahi
 
XML and Web Services with Groovy
XML and Web Services with GroovyXML and Web Services with Groovy
XML and Web Services with GroovyPaul King
 
Test-Driven Development Overview
Test-Driven Development OverviewTest-Driven Development Overview
Test-Driven Development OverviewRob Myers
 
Exploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentExploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentJayaprakash R
 
Test-Driven Development for Developers: Plain and Simple
Test-Driven Development for Developers: Plain and SimpleTest-Driven Development for Developers: Plain and Simple
Test-Driven Development for Developers: Plain and SimpleTechWell
 
Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Altece
 
HackU 2013 : Introduction to Android programming
HackU 2013 : Introduction to Android programmingHackU 2013 : Introduction to Android programming
HackU 2013 : Introduction to Android programmingkalmeshhn
 
Microservices and functional programming
Microservices and functional programmingMicroservices and functional programming
Microservices and functional programmingMichael Neale
 
6 Programming Languages under investigation
6 Programming Languages under investigation6 Programming Languages under investigation
6 Programming Languages under investigationHosam Aly
 
La programmation concurrente par flux de données
La programmation concurrente par flux de donnéesLa programmation concurrente par flux de données
La programmation concurrente par flux de donnéesMicrosoft
 
Modify the bouncing ball example demonstrated/tutorialoutlet
Modify the bouncing ball example demonstrated/tutorialoutletModify the bouncing ball example demonstrated/tutorialoutlet
Modify the bouncing ball example demonstrated/tutorialoutletCleasbyz
 
ACCU 2013 Taking Scala into the Enterpise
ACCU 2013 Taking Scala into the EnterpiseACCU 2013 Taking Scala into the Enterpise
ACCU 2013 Taking Scala into the EnterpisePeter Pilgrim
 
Design patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjsDesign patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjsRavi Bhadauria
 
Open source report writing tools for IBM i Vienna 2012
Open source report writing tools for IBM i  Vienna 2012Open source report writing tools for IBM i  Vienna 2012
Open source report writing tools for IBM i Vienna 2012COMMON Europe
 
Deep Dive Into Swift
Deep Dive Into SwiftDeep Dive Into Swift
Deep Dive Into SwiftSarath C
 
Unethical JavaScript - Giorgio Natili - Codemotion Rome 2017
Unethical JavaScript - Giorgio Natili - Codemotion Rome 2017Unethical JavaScript - Giorgio Natili - Codemotion Rome 2017
Unethical JavaScript - Giorgio Natili - Codemotion Rome 2017Codemotion
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascriptAyush Sharma
 

Similar to Essential Test-Driven Development (20)

Essential Test-Driven Development
Essential Test-Driven DevelopmentEssential Test-Driven Development
Essential Test-Driven Development
 
Dependency Injection @ AngularJS
Dependency Injection @ AngularJSDependency Injection @ AngularJS
Dependency Injection @ AngularJS
 
XML and Web Services with Groovy
XML and Web Services with GroovyXML and Web Services with Groovy
XML and Web Services with Groovy
 
Test-Driven Development Overview
Test-Driven Development OverviewTest-Driven Development Overview
Test-Driven Development Overview
 
Exploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App developmentExploring Kotlin language basics for Android App development
Exploring Kotlin language basics for Android App development
 
Test-Driven Development for Developers: Plain and Simple
Test-Driven Development for Developers: Plain and SimpleTest-Driven Development for Developers: Plain and Simple
Test-Driven Development for Developers: Plain and Simple
 
Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)Objective-C A Beginner's Dive (with notes)
Objective-C A Beginner's Dive (with notes)
 
Angular from Scratch
Angular from ScratchAngular from Scratch
Angular from Scratch
 
HackU 2013 : Introduction to Android programming
HackU 2013 : Introduction to Android programmingHackU 2013 : Introduction to Android programming
HackU 2013 : Introduction to Android programming
 
Microservices and functional programming
Microservices and functional programmingMicroservices and functional programming
Microservices and functional programming
 
6 Programming Languages under investigation
6 Programming Languages under investigation6 Programming Languages under investigation
6 Programming Languages under investigation
 
La programmation concurrente par flux de données
La programmation concurrente par flux de donnéesLa programmation concurrente par flux de données
La programmation concurrente par flux de données
 
Modify the bouncing ball example demonstrated/tutorialoutlet
Modify the bouncing ball example demonstrated/tutorialoutletModify the bouncing ball example demonstrated/tutorialoutlet
Modify the bouncing ball example demonstrated/tutorialoutlet
 
ACCU 2013 Taking Scala into the Enterpise
ACCU 2013 Taking Scala into the EnterpiseACCU 2013 Taking Scala into the Enterpise
ACCU 2013 Taking Scala into the Enterpise
 
Day 1
Day 1Day 1
Day 1
 
Design patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjsDesign patterns in java script, jquery, angularjs
Design patterns in java script, jquery, angularjs
 
Open source report writing tools for IBM i Vienna 2012
Open source report writing tools for IBM i  Vienna 2012Open source report writing tools for IBM i  Vienna 2012
Open source report writing tools for IBM i Vienna 2012
 
Deep Dive Into Swift
Deep Dive Into SwiftDeep Dive Into Swift
Deep Dive Into Swift
 
Unethical JavaScript - Giorgio Natili - Codemotion Rome 2017
Unethical JavaScript - Giorgio Natili - Codemotion Rome 2017Unethical JavaScript - Giorgio Natili - Codemotion Rome 2017
Unethical JavaScript - Giorgio Natili - Codemotion Rome 2017
 
Design patterns in javascript
Design patterns in javascriptDesign patterns in javascript
Design patterns in javascript
 

More from TechWell

Failing and Recovering
Failing and RecoveringFailing and Recovering
Failing and RecoveringTechWell
 
Instill a DevOps Testing Culture in Your Team and Organization
Instill a DevOps Testing Culture in Your Team and Organization Instill a DevOps Testing Culture in Your Team and Organization
Instill a DevOps Testing Culture in Your Team and Organization TechWell
 
Test Design for Fully Automated Build Architecture
Test Design for Fully Automated Build ArchitectureTest Design for Fully Automated Build Architecture
Test Design for Fully Automated Build ArchitectureTechWell
 
System-Level Test Automation: Ensuring a Good Start
System-Level Test Automation: Ensuring a Good StartSystem-Level Test Automation: Ensuring a Good Start
System-Level Test Automation: Ensuring a Good StartTechWell
 
Build Your Mobile App Quality and Test Strategy
Build Your Mobile App Quality and Test StrategyBuild Your Mobile App Quality and Test Strategy
Build Your Mobile App Quality and Test StrategyTechWell
 
Testing Transformation: The Art and Science for Success
Testing Transformation: The Art and Science for SuccessTesting Transformation: The Art and Science for Success
Testing Transformation: The Art and Science for SuccessTechWell
 
Implement BDD with Cucumber and SpecFlow
Implement BDD with Cucumber and SpecFlowImplement BDD with Cucumber and SpecFlow
Implement BDD with Cucumber and SpecFlowTechWell
 
Develop WebDriver Automated Tests—and Keep Your Sanity
Develop WebDriver Automated Tests—and Keep Your SanityDevelop WebDriver Automated Tests—and Keep Your Sanity
Develop WebDriver Automated Tests—and Keep Your SanityTechWell
 
Eliminate Cloud Waste with a Holistic DevOps Strategy
Eliminate Cloud Waste with a Holistic DevOps StrategyEliminate Cloud Waste with a Holistic DevOps Strategy
Eliminate Cloud Waste with a Holistic DevOps StrategyTechWell
 
Transform Test Organizations for the New World of DevOps
Transform Test Organizations for the New World of DevOpsTransform Test Organizations for the New World of DevOps
Transform Test Organizations for the New World of DevOpsTechWell
 
The Fourth Constraint in Project Delivery—Leadership
The Fourth Constraint in Project Delivery—LeadershipThe Fourth Constraint in Project Delivery—Leadership
The Fourth Constraint in Project Delivery—LeadershipTechWell
 
Resolve the Contradiction of Specialists within Agile Teams
Resolve the Contradiction of Specialists within Agile TeamsResolve the Contradiction of Specialists within Agile Teams
Resolve the Contradiction of Specialists within Agile TeamsTechWell
 
Pin the Tail on the Metric: A Field-Tested Agile Game
Pin the Tail on the Metric: A Field-Tested Agile GamePin the Tail on the Metric: A Field-Tested Agile Game
Pin the Tail on the Metric: A Field-Tested Agile GameTechWell
 
Agile Performance Holarchy (APH)—A Model for Scaling Agile Teams
Agile Performance Holarchy (APH)—A Model for Scaling Agile TeamsAgile Performance Holarchy (APH)—A Model for Scaling Agile Teams
Agile Performance Holarchy (APH)—A Model for Scaling Agile TeamsTechWell
 
A Business-First Approach to DevOps Implementation
A Business-First Approach to DevOps ImplementationA Business-First Approach to DevOps Implementation
A Business-First Approach to DevOps ImplementationTechWell
 
Databases in a Continuous Integration/Delivery Process
Databases in a Continuous Integration/Delivery ProcessDatabases in a Continuous Integration/Delivery Process
Databases in a Continuous Integration/Delivery ProcessTechWell
 
Mobile Testing: What—and What Not—to Automate
Mobile Testing: What—and What Not—to AutomateMobile Testing: What—and What Not—to Automate
Mobile Testing: What—and What Not—to AutomateTechWell
 
Cultural Intelligence: A Key Skill for Success
Cultural Intelligence: A Key Skill for SuccessCultural Intelligence: A Key Skill for Success
Cultural Intelligence: A Key Skill for SuccessTechWell
 
Turn the Lights On: A Power Utility Company's Agile Transformation
Turn the Lights On: A Power Utility Company's Agile TransformationTurn the Lights On: A Power Utility Company's Agile Transformation
Turn the Lights On: A Power Utility Company's Agile TransformationTechWell
 

More from TechWell (20)

Failing and Recovering
Failing and RecoveringFailing and Recovering
Failing and Recovering
 
Instill a DevOps Testing Culture in Your Team and Organization
Instill a DevOps Testing Culture in Your Team and Organization Instill a DevOps Testing Culture in Your Team and Organization
Instill a DevOps Testing Culture in Your Team and Organization
 
Test Design for Fully Automated Build Architecture
Test Design for Fully Automated Build ArchitectureTest Design for Fully Automated Build Architecture
Test Design for Fully Automated Build Architecture
 
System-Level Test Automation: Ensuring a Good Start
System-Level Test Automation: Ensuring a Good StartSystem-Level Test Automation: Ensuring a Good Start
System-Level Test Automation: Ensuring a Good Start
 
Build Your Mobile App Quality and Test Strategy
Build Your Mobile App Quality and Test StrategyBuild Your Mobile App Quality and Test Strategy
Build Your Mobile App Quality and Test Strategy
 
Testing Transformation: The Art and Science for Success
Testing Transformation: The Art and Science for SuccessTesting Transformation: The Art and Science for Success
Testing Transformation: The Art and Science for Success
 
Implement BDD with Cucumber and SpecFlow
Implement BDD with Cucumber and SpecFlowImplement BDD with Cucumber and SpecFlow
Implement BDD with Cucumber and SpecFlow
 
Develop WebDriver Automated Tests—and Keep Your Sanity
Develop WebDriver Automated Tests—and Keep Your SanityDevelop WebDriver Automated Tests—and Keep Your Sanity
Develop WebDriver Automated Tests—and Keep Your Sanity
 
Ma 15
Ma 15Ma 15
Ma 15
 
Eliminate Cloud Waste with a Holistic DevOps Strategy
Eliminate Cloud Waste with a Holistic DevOps StrategyEliminate Cloud Waste with a Holistic DevOps Strategy
Eliminate Cloud Waste with a Holistic DevOps Strategy
 
Transform Test Organizations for the New World of DevOps
Transform Test Organizations for the New World of DevOpsTransform Test Organizations for the New World of DevOps
Transform Test Organizations for the New World of DevOps
 
The Fourth Constraint in Project Delivery—Leadership
The Fourth Constraint in Project Delivery—LeadershipThe Fourth Constraint in Project Delivery—Leadership
The Fourth Constraint in Project Delivery—Leadership
 
Resolve the Contradiction of Specialists within Agile Teams
Resolve the Contradiction of Specialists within Agile TeamsResolve the Contradiction of Specialists within Agile Teams
Resolve the Contradiction of Specialists within Agile Teams
 
Pin the Tail on the Metric: A Field-Tested Agile Game
Pin the Tail on the Metric: A Field-Tested Agile GamePin the Tail on the Metric: A Field-Tested Agile Game
Pin the Tail on the Metric: A Field-Tested Agile Game
 
Agile Performance Holarchy (APH)—A Model for Scaling Agile Teams
Agile Performance Holarchy (APH)—A Model for Scaling Agile TeamsAgile Performance Holarchy (APH)—A Model for Scaling Agile Teams
Agile Performance Holarchy (APH)—A Model for Scaling Agile Teams
 
A Business-First Approach to DevOps Implementation
A Business-First Approach to DevOps ImplementationA Business-First Approach to DevOps Implementation
A Business-First Approach to DevOps Implementation
 
Databases in a Continuous Integration/Delivery Process
Databases in a Continuous Integration/Delivery ProcessDatabases in a Continuous Integration/Delivery Process
Databases in a Continuous Integration/Delivery Process
 
Mobile Testing: What—and What Not—to Automate
Mobile Testing: What—and What Not—to AutomateMobile Testing: What—and What Not—to Automate
Mobile Testing: What—and What Not—to Automate
 
Cultural Intelligence: A Key Skill for Success
Cultural Intelligence: A Key Skill for SuccessCultural Intelligence: A Key Skill for Success
Cultural Intelligence: A Key Skill for Success
 
Turn the Lights On: A Power Utility Company's Agile Transformation
Turn the Lights On: A Power Utility Company's Agile TransformationTurn the Lights On: A Power Utility Company's Agile Transformation
Turn the Lights On: A Power Utility Company's Agile Transformation
 

Recently uploaded

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Mattias Andersson
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDGMarianaLemus7
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfjimielynbastida
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsAndrey Dotsenko
 

Recently uploaded (20)

Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?Are Multi-Cloud and Serverless Good or Bad?
Are Multi-Cloud and Serverless Good or Bad?
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
APIForce Zurich 5 April Automation LPDG
APIForce Zurich 5 April  Automation LPDGAPIForce Zurich 5 April  Automation LPDG
APIForce Zurich 5 April Automation LPDG
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Science&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdfScience&tech:THE INFORMATION AGE STS.pdf
Science&tech:THE INFORMATION AGE STS.pdf
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
Transcript: #StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

Essential Test-Driven Development

  • 1. 9/9/13   As you enter the room… 1.  Take a 3x5 card or piece of paper, create two columns. 2.  Write these skills in the first column: TDD, Refactoring, OO, Java (or C#), Eclipse (or IDEA or VisualStudio) 3.  For each skill, rate yourself from 0 (never heard of it) to 10 (invented it), and record in the second column. 4.  Find someone (a) whom you don’t usually work with; and (b) who has somewhat complementary skill levels (with them, your average is 4 to 6). Write down this person’s name, but only if both a and b are true. 5.  Repeat step 4 until you have two names. 9 September 2013 © Agile Institute 2008-2013 1 …get comfortable. 1.  Choose someone from your list to work with. 2.  Gather your belongings and select a workstation for you and your new lab partner. 3.  Settle in at that workstation. 9 September 2013 © Agile Institute 2008-2013 2 1  
  • 2. 9/9/13   Café Essential Test-Driven Development Rob Myers for Agile Development Practices East 12 November 2013 9 September 2013 © Agile Institute 2008-2013 3 © Agile Institute 2008-2013 4 Unit testing is soooo DEPRESSING 9 September 2013 2  
  • 3. 9/9/13   TDD is fun, and provides much more than just unit-tests! 9 September 2013 © Agile Institute 2008-2013 5 “The results of the case studies indicate that the pre-release defect density of the four products decreased between 40% and 90% relative to similar projects that did not use the TDD practice. Subjectively, the teams experienced a 15–35% increase in initial development time after adopting TDD.” http://research.microsoft.com/en-us/projects/esm/nagappan_tdd.pdf, Nagappan et al, © Springer Science + Business Media, LLC 2008 9 September 2013 © Agile Institute 2008-2013 6 3  
  • 4. 9/9/13   TDD Demo 9 September 2013 © Agile Institute 2008-2013 7 No Magic import org.junit.*; public class FooTests { @Test public void fooBarIsBaz() { Foo foo = new Foo(); Assert.assertEquals("Baz", foo.bar()); } } 9 September 2013 © Agile Institute 2008-2013 8 4  
  • 5. 9/9/13   Requirements & Conventions import org.junit.*; public class FooTests { @Test public void fooBarIsBaz() { Foo foo = new Foo(); Assert.assertEquals("Baz", foo.bar()); } } Expected 9 September 2013 Actual © Agile Institute 2008-2013 9 Basic UML Class Diagrams Bar Foo - int privateVariable + void AbstractMethod( object parameter) + int PublicMethod() Baz - void PrivateMethod() 9 September 2013 © Agile Institute 2008-2013 10 5  
  • 6. 9/9/13   Global Currency Money-Market Account 9 September 2013 © Agile Institute 2008-2013 11 Global ATM Access 9 September 2013 © Agile Institute 2008-2013 12 6  
  • 7. 9/9/13   Stories •  As Rob the US account holder, I want to be able to withdraw USD from a US ATM, but select which currency holdings to withdraw from. •  As Rob, traveling in Europe, I want to be able to withdraw EUR from either my EUR holdings or my USD holdings. The default should be the most beneficial to me at the time. •  Shortly after the end of each month, I want to receive a report of my holdings and balance. The total balance should appear in the currency of my account address (USD). 9 September 2013 © Agile Institute 2008-2013 13 Primary Objects Currency Account Holding 9 September 2013 © Agile Institute 2008-2013 14 7  
  • 8. 9/9/13   More Detail Currency Holding value currency currencyConverter convert value to another currency 9 September 2013 CurrencyConverter © Agile Institute 2008-2013 15 Start Simple To Do q When currencies are the same. q When value is zero. 9 September 2013 © Agile Institute 2008-2013 16 8  
  • 9. 9/9/13   Specification, and Interface @Test public void givesSameValueWhenSameCurrencyRequested() { CurrencyConverter converter = new CurrencyConverter(); String sameCurrency = "USD"; double sameValue = 100.0000; double converted = converter.convert( sameValue, sameCurrency, sameCurrency); Assert.assertEquals(sameValue, converted, 0.00004); } Will not compile. L 9 September 2013 © Agile Institute 2008-2013 17 “Thank You, But…” public class CurrencyConverter { public double convert( double value, String from, String to) { throw new RuntimeException( "D'oh! convert() not YET implemented!"); } } 9 September 2013 © Agile Institute 2008-2013 18 9  
  • 10. 9/9/13   “…I Want to See it Fail Successfully” public class CurrencyConverter { public double convert( double value, String from, String to) { return 0.0; } } 9 September 2013 © Agile Institute 2008-2013 19 Technique: “Fake It” public class CurrencyConverter { public double convert( double value, String from, String to) { return 100.0; } } 9 September 2013 © Agile Institute 2008-2013 20 10  
  • 11. 9/9/13   a. Refactor Away the Duplication @Test public void givesSameValueWhenSameCurrencyRequested() { CurrencyConverter converter = new CurrencyConverter(); String sameCurrency = "USD"; double sameValue = 100.0000; double converted = converter.convert( sameValue, sameCurrency, sameCurrency); Assert.assertEquals(sameValue, converted, 0.00004); } public double convert( double value, String from, String to) { return 100.0; } 9 September 2013 © Agile Institute 2008-2013 21 b. Triangulate 9 September 2013 © Agile Institute 2008-2013 22 11  
  • 12. 9/9/13   We don’t add any behavior without a failing test… Rodin’s The Thinker, photo by CJ on Wikipedia 9 September 2013 © Agile Institute 2008-2013 23 Technique: “Triangulation” @Test public void givesZeroWhenValueIsZero() { CurrencyConverter converter = new CurrencyConverter(); double zero = 0.0000; double converted = converter.convert( zero, "USD", "EUR"); Assert.assertEquals(zero, converted, 0.00004); } 9 September 2013 © Agile Institute 2008-2013 24 12  
  • 13. 9/9/13   Still “Fake”? public class CurrencyConverter { public double convert( double value, String from, String to) { return value; } } 9 September 2013 © Agile Institute 2008-2013 25 Maintain the Tests @Test public void givesZeroWhenValueIsZero() { CurrencyConverter converter = new CurrencyConverter(); // ... } @Test public void givesSameValueWhenSameCurrencyRequested() { CurrencyConverter converter = new CurrencyConverter(); // ... } 9 September 2013 © Agile Institute 2008-2013 26 13  
  • 14. 9/9/13   @Before Runs Before Each Test private CurrencyConverter converter; @Before public void initialize() { converter = new CurrencyConverter(); } @Test public // } @Test public // } void givesZeroWhenValueIsZero() { ... void givesSameValueWhenSameCurrencyRequested() { ... 9 September 2013 © Agile Institute 2008-2013 27 What is the Expected Answer? @Test public void convertsDollarsToEuros() { double converted = converter.convert( 100.0000, "USD", "EUR"); Assert.assertEquals(???, converted, 0.00004); } 9 September 2013 © Agile Institute 2008-2013 28 14  
  • 15. 9/9/13   Let’s Invent a Scenario… @Test public void convertsDollarsToEuros() { double converted = converter.convert( 100.0000, "USD", "EUR"); Assert.assertEquals(50.0000, converted, 0.00004); } 9 September 2013 © Agile Institute 2008-2013 29 …“Fake It”… public double convert( double value, String from, String to) { if (to.equals(from)) return value; return value * 0.5000; } 9 September 2013 © Agile Institute 2008-2013 30 15  
  • 16. 9/9/13   …Refactor… public double convert( double value, String from, String to) { if (to.Equals(from)) return value; return value * conversionRate(from, to); } private double conversionRate(String from, String to) { return 0.5000; } 9 September 2013 © Agile Institute 2008-2013 31 …And Make a Note of It To Do ü When currencies are the same. ü When value is zero. q Fix the hard-coded conversionRate 9 September 2013 © Agile Institute 2008-2013 32 16  
  • 17. 9/9/13   Well, What is It??? Where does it come from? 9 September 2013 © Agile Institute 2008-2013 33 Circumstantial Coupling? CurrencyConverter 9 September 2013 © Agile Institute 2008-2013 34 17  
  • 18. 9/9/13   Managing the Transaction Account CurrencyConverter Holding Holding Holding Holding 9 September 2013 ConversionRates © Agile Institute 2008-2013 35 Another Object Emerges To Do ü When currencies are the same. ü When value is zero. q Fix hard-coded conversionRate(). q Write ConversionRates. q Make a factory for ConversionRates that uses the FOREX.com Web Service. 9 September 2013 © Agile Institute 2008-2013 36 18  
  • 19. 9/9/13   New Test Class import org.junit.Assert; import org.junit.Test; public class ConversionRatesTest { @Test public void storesAndRetrievesRates() { ConversionRates rates = new ConversionRates(); String from = "USD"; String to = "EUR"; double rate = 0.7424; rates.putRate(from, to, rate); Assert.assertEquals(rate, rates.getRate(from, to), 0.0004); } } 9 September 2013 © Agile Institute 2008-2013 37 Fail public class ConversionRates { public void putRate(String from, String to, double rate) { } public double getRate(String from, String to) { return 0; } } 9 September 2013 © Agile Institute 2008-2013 38 19  
  • 20. 9/9/13   Technique: “Obvious Implementation” import java.util.HashMap; import java.util.Map; public class ConversionRates { private Map<String, Double> rates = new HashMap<String, Double>(); public void putRate(String from, String to, double rate) { rates.put(from + to, rate); } public double getRate(String from, String to) { return rates.get(from + to); } } 9 September 2013 © Agile Institute 2008-2013 39 Isolate Behavior public class ConversionRates { private Map<String, Double> rates = new HashMap<String, Double>(); public void putRate(String from, String to, double rate) { rates.put(key(from, to), rate); } public double getRate(String from, String to) { return rates.get(key(from, to)); } private String key(String from, String to) { return from + to; } } 9 September 2013 © Agile Institute 2008-2013 40 20  
  • 21. 9/9/13   Next? To Do ü When currencies are the same. ü When value is zero. q Fix hard-coded conversionRate(). ü Write ConversionRates. q Make a factory for ConversionRates that uses the FOREX.com Web Service. 9 September 2013 © Agile Institute 2008-2013 41 Fix @Before Method public class CurrencyConverterTests { private CurrencyConverter converter; @Before public void initialize() { ConversionRates rates = new ConversionRates(); rates.putRate("USD", "EUR", 0.5000); converter = new CurrencyConverter(rates); } // ... 9 September 2013 © Agile Institute 2008-2013 42 21  
  • 22. 9/9/13   Partially Refactored… public class CurrencyConverter { private ConversionRates rates; public CurrencyConverter(ConversionRates rates) { this.rates = rates; } private double conversionRate(String from, String to) { return 0.5000; } // ... 9 September 2013 © Agile Institute 2008-2013 43 Replace the Hard-Coded Value public class CurrencyConverter { private ConversionRates rates; public CurrencyConverter(ConversionRates rates) { this.rates = rates; } private double conversionRate(String from, String to) { return rates.getRate(from, to); } // ... 9 September 2013 © Agile Institute 2008-2013 44 22  
  • 23. 9/9/13   What Remains? To Do ü When currencies are the same. ü When value is zero. ü Fix hard-coded conversionRate(). ü Write ConversionRates. q Make a factory for ConversionRates that uses the FOREX.com Web Service. 9 September 2013 © Agile Institute 2008-2013 45 What is the Missing Piece? ConversionRates rates = ConversionRates.byAccountAnd???( account, 9 September 2013 © Agile Institute 2008-2013 ???); 46 23  
  • 24. 9/9/13   Ask What If…? To Do q Make a byAccountAndDate() factory for ConversionRates that uses the FOREX.com Web Service. q ConversionRates returns 1/rate if inverse rate found. q ConversionRates throws when rate not found. 9 September 2013 © Agile Institute 2008-2013 47 Testing Exceptional Behavior @Test(expected=RateNotFoundException.class) public void throwsExceptionIfRateNotFoundII() { ConversionRates rates = new ConversionRates(); String from = "BAR"; String to = "BAZ"; rates.getRate(from, to); } 9 September 2013 © Agile Institute 2008-2013 48 24  
  • 25. 9/9/13   A New Exception public class RateNotFoundException extends RuntimeException { } 9 September 2013 © Agile Institute 2008-2013 49 9 September 2013 © Agile Institute 2008-2013 50 25  
  • 26. 9/9/13   Back in ConversionRates public double getRate(String from, String to) { if (!rates.containsKey(key(from, to))) throw new RateNotFoundException(); return rates.get(key(from, to)); } 9 September 2013 © Agile Institute 2008-2013 1.  Write one unit test. 51 steps 2.  Build or add to the object under test until everything compiles. 3.  Red: Watch the test fail! 4.  Green: Make all the tests pass by changing the object under test. 5.  Clean: Refactor mercilessly! 6.  Repeat. 9 September 2013 © Agile Institute 2008-2013 52 26  
  • 27. 9/9/13   Runs all the tests. Expresses every idea required. Says everything once and only once. Has no superfluous parts. 9 September 2013 © Agile Institute 2008-2013 53 Exercise A: Password-Strength Checker In order to be an acceptable password, a string must: q Have a length greater than 7 characters. q Contain at least one alphabetic character. q Contain at least one digit. 9 September 2013 © Agile Institute 2008-2013 54 27  
  • 28. 9/9/13   1.  Write one unit test. steps 2.  Build or add to the object under test until everything compiles. 3.  Red: Watch the test fail! 4.  Green: Make all the tests pass by changing the object under test. 5.  Clean: Refactor mercilessly! 6.  Repeat. 9 September 2013 © Agile Institute 2008-2013 55 Iteration 2 •  Admins and regular users: •  Admin passwords must also... •  Be > 10 chars long •  Contain a special character •  People want to know all the reasons why their password has failed. •  Other stronger rules may apply later. ;-) •  HINT: What is varying most frequently? Be sure to take a break when you need one! 9 September 2013 © Agile Institute 2008-2013 56 28  
  • 29. 9/9/13   1.  Write one unit test. steps 2.  Build or add to the object under test until everything compiles. 3.  Red: Watch the test fail! 4.  Green: Make all the tests pass by changing the object under test. 5.  Clean: Refactor mercilessly! 6.  Repeat. 9 September 2013 © Agile Institute 2008-2013 57 1.  _______________________________________ 2.  _______________________________________ 3.  _______________________________________ CLOSING 9 September 2013 © Agile Institute 2008-2013 58 29  
  • 30. 9/9/13   9 September 2013 © Agile Institute 2008-2013 59 Rob.Myers@agileInstitute.com http://PowersOfTwo.agileInstitute.com/ @agilecoach 9 September 2013 © Agile Institute 2008-2013 60 30