TDD Overview

Preview:

DESCRIPTION

Million Feet Overview of Test Driven Development. (not a very technical presentation).

Citation preview

Test Driven DevelopmentEmbrace Uncertainty

Naresh JainTwitter: @nashjain

http://blogs.agilefaqs.com

Licensed Under Creative Commons by Naresh Jain1Friday, October 2, 2009

TDD RhythmTest, Code, Refactor

2Friday, October 2, 2009

Add a Test

TDD RhythmTest, Code, Refactor

2Friday, October 2, 2009

Add a Test

Run the Test

TDD RhythmTest, Code, Refactor

2Friday, October 2, 2009

Add a Test

Run the TestPass

TDD RhythmTest, Code, Refactor

2Friday, October 2, 2009

Add a Test

Run the Test

Fail

Pass

TDD RhythmTest, Code, Refactor

2Friday, October 2, 2009

Add a Test

Run the Test

Make a little change

Fail

Pass

TDD RhythmTest, Code, Refactor

2Friday, October 2, 2009

Add a Test

Run the Test

Make a little change

Run the Test

Fail

Pass

TDD RhythmTest, Code, Refactor

2Friday, October 2, 2009

Add a Test

Run the Test

Make a little change

Run the Test

Fail

Fail

Pass

TDD RhythmTest, Code, Refactor

2Friday, October 2, 2009

Add a Test

Run the Test

Make a little change

Run the Test

Fail

Pass

Fail

Pass

TDD RhythmTest, Code, Refactor

2Friday, October 2, 2009

Add a Test

Run the Test

Make a little change

Run the Test

Refactor

Fail

Pass

Fail

Pass

TDD RhythmTest, Code, Refactor

2Friday, October 2, 2009

Add a Test

Run the Test

Make a little change

Run the Test

Refactor

Fail

Pass

Fail

Pass

TDD RhythmTest, Code, Refactor

2Friday, October 2, 2009

Add a Test

Run the Test

Make a little change

Run the Test

Refactor

Fail

Pass

Fail

Pass

TDD RhythmTest, Code, Refactor

2Friday, October 2, 2009

Add a Test

Run the Test

Make a little change

Run the Test

Refactor

Fail

Pass

Fail

Pass

TDD RhythmTest, Code, Refactor

2Friday, October 2, 2009

But....

3Friday, October 2, 2009

ROI?

Is there a p

roblem here?

Extra Work?

How to Start?Who? When?Productivity?

3Friday, October 2, 2009

Continuum

4Friday, October 2, 2009

5Friday, October 2, 2009

New to Agile

Post Agile

5Friday, October 2, 2009

New to Agile

Post Agile

New to TDDExpert TDDPractitioners

5Friday, October 2, 2009

Me

6Friday, October 2, 2009

7Friday, October 2, 2009

Mumbai8Friday, October 2, 2009

9Friday, October 2, 2009

10Friday, October 2, 2009

We don’t travel like this

11Friday, October 2, 2009

We are getting there...

12Friday, October 2, 2009

Tech Talks!

13Friday, October 2, 2009

14Friday, October 2, 2009

15Friday, October 2, 2009

16Friday, October 2, 2009

Warmup Scenario

17Friday, October 2, 2009

18Friday, October 2, 2009

Pick one scenario and in relation to your scenario, what are the specific observable results that will tell you that the activity has been successfully completed?

18Friday, October 2, 2009

Pick one scenario and in relation to your scenario, what are the specific observable results that will tell you that the activity has been successfully completed?

Going out for Movie (THX sound and Digital projection)

18Friday, October 2, 2009

Pick one scenario and in relation to your scenario, what are the specific observable results that will tell you that the activity has been successfully completed?

Going out for Movie (THX sound and Digital projection)

Going out for meal (one veg.)

18Friday, October 2, 2009

Pick one scenario and in relation to your scenario, what are the specific observable results that will tell you that the activity has been successfully completed?

Going out for Movie (THX sound and Digital projection)

Going out for meal (one veg.)

Going shopping ($50)[10 Minutes]

18Friday, October 2, 2009

Pick one scenario and in relation to your scenario, what are the specific observable results that will tell you that the activity has been successfully completed?

Going out for Movie (THX sound and Digital projection)

Going out for meal (one veg.)

Going shopping ($50)[10 Minutes]

Present back to the group your findings. [3 minutes per group]

18Friday, October 2, 2009

Acceptance Criteria and Tests

A critical piece of Agile

19Friday, October 2, 2009

Acceptance CriteriaIs a set of conditions that the Story must meet for it to be accepted as complete

Is typically provided by the customer or product owner.

Is not a replacement for conversation.

Is one of the results of the conversation

Acceptance Criteria are NOT tests

20Friday, October 2, 2009

Given [Precondition]

When [Actor + Action]

Then [Observable Result]

21Friday, October 2, 2009

Acceptance Criteria

Examples (data + scenarios)

Acceptance Tests

22Friday, October 2, 2009

Acceptance Criteria

Examples (data + scenarios)

Acceptance Tests

+

22Friday, October 2, 2009

DemoRoman Numerals to Decimal Conversion Example

23Friday, October 2, 2009

Analysis

Design

Implementation

DFDERD

DDST

1 May 1 Nov1 Jul 1 Sep

24Friday, October 2, 2009

Are we building the right product?

Are we building the product right?

Business Facing

Technology/Implementation Facing

25Friday, October 2, 2009

Brian Marick’s Test Categorization

Business Facing

Technology/Implementation Facing

Supp

orts

Pro

gram

min

gC

ritique product

26Friday, October 2, 2009

Business Facing

Technology/Implementation Facing

Dri

ves

Dev

elop

men

t Critique product

It Helps to think...

27Friday, October 2, 2009

Business Facing

Technology/Implementation Facing

Dri

ves

Dev

elop

men

t Critique product

Unit Testing

It Helps to think...

27Friday, October 2, 2009

Business Facing

Technology/Implementation Facing

Dri

ves

Dev

elop

men

t Critique product

Unit Testing

Acceptance Testing Low-fi prototypes

It Helps to think...

27Friday, October 2, 2009

Business Facing

Technology/Implementation Facing

Dri

ves

Dev

elop

men

t Critique product

Unit Testing

Acceptance Testing Low-fi prototypes

Exploratory TestingUI and Usability Testing

It Helps to think...

27Friday, October 2, 2009

Business Facing

Technology/Implementation Facing

Dri

ves

Dev

elop

men

t Critique product

Unit Testing

Acceptance Testing Low-fi prototypes

Exploratory TestingUI and Usability Testing

Performance TestingSystem Tests

It Helps to think...

27Friday, October 2, 2009

Acceptance Test Driven

28Friday, October 2, 2009

Acceptance Test Driven

Story

28Friday, October 2, 2009

Acceptance Test Driven

Story

Acceptance Criteria

28Friday, October 2, 2009

Acceptance Test DrivenIteration

Story

Acceptance Criteria

28Friday, October 2, 2009

Acceptance Test DrivenIteration

Automated Acceptance

Tests

Story

Acceptance Criteria

28Friday, October 2, 2009

Acceptance Test DrivenIteration

Automated Acceptance

Tests

Story

Acceptance Criteria

Automated Unit Test

28Friday, October 2, 2009

Acceptance Test DrivenIteration

Automated Acceptance

Tests

AutomatedAcceptance

Tests

Story

Acceptance Criteria

Automated Unit Test

28Friday, October 2, 2009

Acceptance Test DrivenIteration

Automated Acceptance

Tests

AutomatedAcceptance

Tests

Story

Acceptance Criteria

ExploratoryTesting

Automated Unit Test

28Friday, October 2, 2009

Acceptance Test DrivenIteration

Automated Acceptance

Tests

AutomatedAcceptance

Tests

Story

Acceptance Criteria

Acceptance Criteria

ExploratoryTesting

Automated Unit Test

28Friday, October 2, 2009

Acceptance Test DrivenIteration

Automated Acceptance

Tests

AutomatedAcceptance

Tests

Story

Acceptance Criteria

Acceptance Criteria

ExploratoryTesting

Automated UI Tests

Automated Unit Test

28Friday, October 2, 2009

Acceptance Test DrivenIteration

Automated Acceptance

Tests

AutomatedAcceptance

Tests

Story

Acceptance Criteria

Acceptance Criteria

ExploratoryTesting

Automated UI Tests

TESTS

PERFORMENCE

Automated Unit Test

28Friday, October 2, 2009

Mike Cohn’s Testing Pyramid

29Friday, October 2, 2009

Mike Cohn’s Testing Pyramid

GUITests

29Friday, October 2, 2009

Mike Cohn’s Testing Pyramid

GUITests

Small in NumberTools: Selenium, Sahi, Watir, Abbot, Frankenstein

29Friday, October 2, 2009

Mike Cohn’s Testing Pyramid

AcceptanceTests

GUITests

Small in NumberTools: Selenium, Sahi, Watir, Abbot, Frankenstein

29Friday, October 2, 2009

Mike Cohn’s Testing Pyramid

AcceptanceTests

GUITests

Small in NumberTools: Selenium, Sahi, Watir, Abbot, Frankenstein

At least one per storyTools: Fit, FitNesse, RSpec, Cucumber

29Friday, October 2, 2009

Mike Cohn’s Testing Pyramid

Unit Tests

AcceptanceTests

GUITests

Small in NumberTools: Selenium, Sahi, Watir, Abbot, Frankenstein

At least one per storyTools: Fit, FitNesse, RSpec, Cucumber

29Friday, October 2, 2009

Mike Cohn’s Testing Pyramid

Unit Tests

AcceptanceTests

GUITests

Small in NumberTools: Selenium, Sahi, Watir, Abbot, Frankenstein

At least one per storyTools: Fit, FitNesse, RSpec, Cucumber

At least one per class or moduleTools: xUnit, TestNG

29Friday, October 2, 2009

Business Tier

View

Data Store

Acceptance Tests

UI

Model and Presenter

30Friday, October 2, 2009

Why care about TDD?

31Friday, October 2, 2009

32Friday, October 2, 2009

# of Lines of Code?

33Friday, October 2, 2009

# of Story Points (estimates)?

34Friday, October 2, 2009

35Friday, October 2, 2009

# of Features developed?

35Friday, October 2, 2009

# of Features tested?

35Friday, October 2, 2009

# of Features deployed?

35Friday, October 2, 2009

# of Features used actively?

35Friday, October 2, 2009

What about Maintenance?

36Friday, October 2, 2009

Stay away from (time hungry) debugger

37Friday, October 2, 2009

Manual (monkey) Checking by

Developers and Tester

38Friday, October 2, 2009

Maintain Focus

39Friday, October 2, 2009

Reduce Wastage: Hand Overs

40Friday, October 2, 2009

Communication

41Friday, October 2, 2009

Living, up-to-date specification

42Friday, October 2, 2009

Communicate Design Decisions

43Friday, October 2, 2009

Learning:Listen to your code

44Friday, October 2, 2009

Baby Steps:Slow down and think

45Friday, October 2, 2009

Confidence

46Friday, October 2, 2009

Testable Code by Design+ Safety Net

47Friday, October 2, 2009

Loosely Coupled Design

48Friday, October 2, 2009

Refactoring

49Friday, October 2, 2009

Test Driven DesignBefore you take the plunge

50Friday, October 2, 2009

Evolutionary Design

51Friday, October 2, 2009

System Metaphor

52Friday, October 2, 2009

Thin Slicing

53Friday, October 2, 2009

Interaction Design

54Friday, October 2, 2009

Tracer Bullets

55Friday, October 2, 2009

Avatars of TDDRule of Diversity

Distrust all claims for “One True Way”

56Friday, October 2, 2009

Business Facing

Technology/Implementation Facing

Dri

ves

Dev

elop

men

t Critique product

Outside In

Inside Out

Brian Marick’s Test Categorization

57Friday, October 2, 2009

Veterinarian Information System

58Friday, October 2, 2009

Outside In: ATDDFitnesse Document:Assertions: 17 right, 0 wrong, 0 ignored, 0 exceptions

com.vis.billing.fixtures.PaidCashBill

account details

account number patient name owner name

1001 Fluffy Dave Atkins

procedure detailsname costRoutine Office Visit 250

Rabies Vaccination 50

billaccount number? owner name? patient name? total? paid?1001 Dave Atkins Fluffy 300 false

procedure details on the billname costRoutine Office Visit 250

Rabies Vaccination 50

pay Cash

patient name? owner name? account number? bill no? payment method? amount paid?

Fluffy Dave Atkins 1001 1 Cash 300

check paid true

check total 0

59Friday, October 2, 2009

Outside In: Output

60Friday, October 2, 2009

ATDD: Another ExampleAcceptance test:class FluffyTest < Test::Unit::TestCase def test_examination_and_shots vet = Veterinarian.new clinic = Clinic.new "Main Line health" dave = Owner.new "Dave" fluffy = Patient.new "Fluffy" dave.has fluffy visit = clinic.visit(fluffy, vet) do |v| v.procedure "Rabies vaccination", 50 end invoice = visit.invoice assert_equal invoice.to_s, <<-INVOICE Routine visit: $200 Rabies vaccination: $50 Total: $250 INVOICE receipt = clinic.pay_for visit, 100 assert_equal receipt.to_s, <<-RECEIPT Paid $100 for Routine visit Paid $0 for Rabies vaccination Outstanding: $150 RECEIPT endend

61Friday, October 2, 2009

Outside In: Output

62Friday, October 2, 2009

Inside Out: Unit TDDpublic class ClinicTest { private Clinic clinic = new Clinic();

@Test public void amountOnTheReceiptShouldMatchBillableAmount() throws Exception { Billable billable = new Billable() { public int totalAmount() { return 0; } }; Account dave = new Account(101, "Dave");

Receipt rcpt = clinic.payCash(dave, billable); assertEquals("Amount on receipt does match procedure cost", billable.totalAmount(), rcpt.getAmount()); }

@Test public void customerPayesBillableAmountForCashTransaction() throws Exception { final int billableAmount = 56; class AmountCharged { int charged; }; final AmountCharged charged = new AmountCharged();

Billable billable = new Billable() { public int totalAmount() { return billableAmount; } };

Account dave = new Account(101, "Dave") { public void charge(int amount) { charged.charged = amount; } };

clinic.payCash(dave, billable); assertEquals("Account is not charged billable amount", billableAmount,charged.charged); }}

public class BillableTest {

private static final Account daveSAccount = new Account(101, "Dave"); private static final List<Service> services = new ArrayList<Service>();

@Test public void totalBillableAmountShouldBeZeroIfNoServicesAreProvided() { Billable bill = new Bill(daveSAccount, services); assertEquals("Total amount is not Zero", 0, bill.totalAmount()); }

@Test public void totalBillableAmountShouldBeTotalOfEachServiceProvided() { services.add(new Procedure("Rabies Vaccination", 250)); services.add(new Procedure("Regular office Visit", 50));

Billable bill = new Bill(daveSAccount, services);

assertEquals("Total Amount is not 300", 300, bill.totalAmount()); }

@After public void cleanUp() { services.clear(); }}

63Friday, October 2, 2009

Inside Out: Output

64Friday, October 2, 2009

Inside Out: Another Examplepublic class ChargeAccountForServices { private static final Billable bill = createMock(Billable.class); private static final Accountable account = createMock(Accountable.class); private static final Clinic clinic = new Clinic();

@Before public void setUp() { reset(account); reset(bill); }

@Test public void shouldMakePaymentsAgainstAnAccount() { account.paid(bill); replay(account); clinic.pay(300, bill, account); verify(account); }

@Test public void shouldHaveZeroAmountDueOnReceiptIfCompletePaymentIsMade() { expect(bill.amount()).andReturn(300); replay(bill); Receipt receipt = clinic.pay(300, bill, account); verify(bill); assertEquals(300, receipt.amount()); assertEquals(0, receipt.amountDue()); }

@Test public void shouldDisplayAmountDueOnTheReceiptIfIncompletePaymentIsMade() { expect(bill.amount()).andReturn(500); replay(bill); Receipt receipt = clinic.pay(300, bill, account); verify(bill); assertEquals(300, receipt.amount()); assertEquals(200, receipt.amountDue()); }}

65Friday, October 2, 2009

public class CreateBillForClientAccount { private static final List<Service> services = new ArrayList<Service>(); private static final Accountable account = createMock(Accountable.class); private Bill bill;

@Before public void setUp() { reset(account); }

@Test public void shouldThrowExceptionIfAccountIsNotDueForPayment() { expect(account.isPaymentDue()).andReturn(false); replay(account); try { new Bill(account, null); } catch (NoPaymentDueException e) { // expected } verify(account); }

@After public void cleanUp() { services.clear(); }

@Test public void shouldCreateABillWithTheTotalCostOfAllTheServices() { IMocksControl control = createControl(); Service rabiesVaccination = control.createMock(Service.class); Service routineVisit = control.createMock(Service.class); services.add(rabiesVaccination); services.add(routineVisit);

expect(account.isPaymentDue()).andReturn(true); expect(account.unpaidServices()).andReturn(services); bill();

expect(rabiesVaccination.cost()).andReturn(250); expect(routineVisit.cost()).andReturn(50);

control.replay();

assertEquals(300, bill.amount()); control.verify(); }

private void bill() throws NoPaymentDueException { replay(account); bill = new Bill(account, null); verify(account); }}

66Friday, October 2, 2009

Inside Out: Output

67Friday, October 2, 2009

Coffee Vending MachineHow would you develop it?

68Friday, October 2, 2009

Feedback

69Friday, October 2, 2009

70Friday, October 2, 2009

71Friday, October 2, 2009

72Friday, October 2, 2009

Visualizing ProficiencyIndustrial Logic’s

e-learningAutomated Analysis of Lab Exerciseshttp://industriallogic.com/elearning/

73Friday, October 2, 2009

74Friday, October 2, 2009

75Friday, October 2, 2009

76Friday, October 2, 2009

77Friday, October 2, 2009

78Friday, October 2, 2009

79Friday, October 2, 2009

Tools & Practices

80Friday, October 2, 2009

Pair Programming

81Friday, October 2, 2009

Continuous Integration

82Friday, October 2, 2009

83Friday, October 2, 2009

Coding Convention+

Static Code Analysis

84Friday, October 2, 2009

Checkstyle

85Friday, October 2, 2009

Code Coverage

86Friday, October 2, 2009

Cobertura

87Friday, October 2, 2009

DB Management

88Friday, October 2, 2009

BeringMigrate4j

89Friday, October 2, 2009

Questions?

naresh@agilefaqs.com

90Friday, October 2, 2009

Recommended