170 likes | 413 Views
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.
E N D
Test Driven Development Ben Hoskins
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
Contract First Development Acceptable and unacceptable input values Preconditions Return values Exception that can occur, and their meanings Side effects Postconditions Invariants Performance guarantees
Behaviour Driven Development Given When Then
Behaviour Driven Development Given Acceptable and unacceptable input values Invariants Preconditions When Event to trigger the function under development Then Return values Exception that can occur, and their meanings Side effects Postconditions Invariants Performance guarantees
Test Driven Development Setup Given Acceptable and unacceptable input values Preconditions Execute function When Event to trigger the function under development Assert Then Return values etc... Tear Down
Test Driven Development ...with a little help from Domain Driven Design @Test publicvoid 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 @Test publicvoid 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 @Test publicvoid 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 @Test publicvoid 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 @Test publicvoid 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 applied to 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