1 / 16

Test Driven Development

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.

judd
Download Presentation

Test Driven Development

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Test Driven Development Ben Hoskins

  2. Test Driven Development

  3. a.k.a. Contract First Development (Design by Contract (C))

  4. a.k.a. Behaviour Driven Development

  5. With a little help from Domain Driven Design

  6. Test Driven Development Setup Exercise function Assert Teardown

  7. Contract First Development Acceptable and unacceptable input values Preconditions Return values Exception that can occur, and their meanings Side effects Postconditions Invariants Performance guarantees

  8. Behaviour Driven Development Given When Then

  9. 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

  10. 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

  11. 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()); }

  12. 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

  13. 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

  14. 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

  15. 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

  16. 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

More Related