16
Test Driven Development Ben Hoskins

Test Driven Development

  • Upload
    judd

  • View
    56

  • Download
    0

Embed Size (px)

DESCRIPTION

Test Driven Development. Ben Hoskins. Test Driven Development. a.k.a. Contract First Development (Design by Contract (C) ). a.k.a. Behaviour Driven Development. With a little help from Domain Driven Design. Test Driven Development Setup Exercise function Assert Teardown. - PowerPoint PPT Presentation

Citation preview

Page 1: Test Driven Development

Test Driven Development

Ben Hoskins

Page 2: Test Driven Development

Test Driven Development

Page 3: Test Driven Development

a.k.a.

Contract First Development

(Design by Contract (C))

Page 4: Test Driven Development

a.k.a.

Behaviour Driven Development

Page 5: Test Driven Development

With a little help from

Domain Driven Design

Page 6: Test Driven Development

Test Driven Development

SetupExercise functionAssertTeardown

Page 7: Test Driven Development

Contract First Development

Acceptable and unacceptable input valuesPreconditionsReturn valuesException that can occur, and their meaningsSide effectsPostconditionsInvariantsPerformance guarantees

Page 8: Test Driven Development

Behaviour Driven Development

GivenWhenThen

Page 9: Test Driven Development

Behaviour Driven Development

GivenAcceptable and unacceptable input valuesInvariantsPreconditions

WhenEvent to trigger the function under development

ThenReturn valuesException that can occur, and their meaningsSide effectsPostconditionsInvariantsPerformance guarantees

Page 10: Test Driven Development

Test Driven Development

SetupGiven

Acceptable and unacceptable input valuesPreconditionsExecute function

WhenEvent to trigger the function under developmentAssert

ThenReturn values etc...Tear Down

Page 11: Test Driven Development

Test Driven Development...with a little help from Domain Driven Design

@Testpublic void canCalculateASingleValue() {

Persona henry = PersonaFactory.sensibleDefaults().and("HenryHumble");String shareValue = TestConstants.SINGLE_SHARE_VALUE;ShareCalculator shareCalculator=new ShareCalculator(driver, shareValue);henry.enterShareAmountInto(shareCalculator);Assert.assertEquals("1.65", shareCalculator.getTotalValue());

}

Page 12: Test Driven Development

Test Driven Development...with a little help from Domain Driven Design

@Testpublic void canCalculateASingleValue() {

Persona henry = PersonaFactory.sensibleDefaults().and("HenryHumble");String shareValue = TestConstants.SINGLE_SHARE_VALUE;ShareCalculator shareCalculator=new ShareCalculator(driver, shareValue);henry.enterShareAmountInto(shareCalculator);Assert.assertEquals("1.65", shareCalculator.getTotalValue());

}

The behaviour is:Share Calculator can calculate a single value

Page 13: Test Driven Development

Test Driven Development...with a little help from Domain Driven Design

@Testpublic void canCalculateASingleValue() {

Persona henry = PersonaFactory.sensibleDefaults().and("HenryHumble");String shareValue = TestConstants.SINGLE_SHARE_VALUE;ShareCalculator shareCalculator=new ShareCalculator(driver, shareValue);henry.enterShareAmountInto(shareCalculator);Assert.assertEquals("1.65", shareCalculator.getTotalValue());

}

The setup / givens are:Henry Humble, a shareholder with 1 share,

A share value of 1.65

Page 14: Test Driven Development

Test Driven Development...with a little help from Domain Driven Design

@Testpublic void canCalculateASingleValue() {

Persona henry = PersonaFactory.sensibleDefaults().and("HenryHumble");String shareValue = TestConstants.SINGLE_SHARE_VALUE;ShareCalculator shareCalculator=new ShareCalculator(driver, shareValue);henry.enterShareAmountInto(shareCalculator);Assert.assertEquals("1.65", shareCalculator.getTotalValue());

}

The execute function / when is:Henry Humble enters his share amount into

The share calculator

Page 15: Test Driven Development

Test Driven Development...with a little help from Domain Driven Design

@Testpublic void canCalculateASingleValue() {

Persona henry = PersonaFactory.sensibleDefaults().and("HenryHumble");String shareValue = TestConstants.SINGLE_SHARE_VALUE;ShareCalculator shareCalculator=new ShareCalculator(driver, shareValue);henry.enterShareAmountInto(shareCalculator);Assert.assertEquals("1.65", shareCalculator.getTotalValue());

}

The assert / then is:The share calculator shows a total value of 1.65

Page 16: Test Driven Development

Test Driven Development...with a little help from Domain Driven Design

In our example there domain driven design was appliedto the test:

The behaviour:A person can input their shares into the share calculator, the share calculator displays the total value of the shares.

The domain:A fixed share price,A share calculator,

can calculate a share price,has the total value available,

A Person, with a fixed amount of shares