Upload
wilfred-hawkins
View
236
Download
0
Embed Size (px)
Citation preview
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
SetupExercise functionAssertTeardown
Contract First Development
Acceptable and unacceptable input valuesPreconditionsReturn valuesException that can occur, and their meaningsSide effectsPostconditionsInvariantsPerformance guarantees
Behaviour Driven Development
GivenWhenThen
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
Test Driven Development
SetupGiven
Acceptable and unacceptable input valuesPreconditionsExecute function
WhenEvent to trigger the function under developmentAssert
ThenReturn values etc...Tear Down
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());
}
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
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
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
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
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