Agile acceptance testing with f sharp


Published on

1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide
  • This talk is entitled “Automate your Agile Acceptance Tests with F#”. Upon compiling the slides I realised that the message I really wanted to get across is “Verifying software....”, provides loads of value as part of an Agile process if done properly. talk was
  • Good vs. BadClass names:Description of arrangement for test vs. Name of class being testedState/Arrangement:Set-up state controlled by the setup fun vs. State created for each test inside the test method.Method names:Description of action and expectation vs. Name of method being tested.What is being tested:Behaviour vs. Member functions.
  • part here is “A good unit test needs to define the behavioural contract”These kind of observations were what prompted Dan North into evolving TDD into BDD, which is what we will discuss next.
  • Just to re-iterate – language is key to good BDD.We don’t want to be speaking a different language to our stake holders.
  • This is a description of what BDD is and how it relates to TDD.
  • In an agile process we specify behaviour in terms of stories and acceptance tests.
  • Stories can be vague without acceptance tests, which leaves them open to scope creep.Scenarios are written in the language of business domain, and are as easy for business participants to understand as they are for developers.
  • Allows: - Shared understanding - Diffusion of language into the If the Sapir-Whorf hypothesis is correct and the language you use effects the way you think then this could be very beneficial.
  • This is a small subset of the frameworks available that enable specification execution.There are many frameworks out and they all tend to follow the gherkin style of interpretation.Therefore they are highly interchangeable without having to change your tests.I have used the bottom three on the right. Each time I have made minor adjustments to allow the double-ticked F# methods.Spec Flow seems to be the framework of choice at the moment largely due to it integration with visual studio. It is very good, and I would recommend it. The only gripe I have is that it requires the features to be stored in an assembly, which doesn’t give you much freedom over where you store your files.
  • I was recently working on an extension to our calculations system that is about 5 years old and written in C++. My first concern upon working on the system was that I didn’t break the current behaviour. Theimplementation had no tests of any sort so I had no safety net. And the scenarios I needed to test were fairly complex and not particularly suited to unit testing. I decided to make use of our XML API. Using the API as my interface I was able to build a test client using F# and use BDD to drive it and verify expectations.
  • GojkoAdzicDon Syme
  • Agile acceptance testing with f sharp

    1. 1. AGILE ACCEPTANCE TESTING WITH F#<br />Zach Bray<br />2010<br />
    2. 2. Outline<br />Test Driven Development (TDD)<br />Implementing TDD<br />Behaviour Driven Development (BDD) <br />Implementing BDD<br />.NET BDD frameworks<br />Case study: Extending a C++ project<br />
    3. 3. Test Driven Development (TDD) cycle<br />
    4. 4. Unit Tests - Good vs. Bad<br />
    5. 5. Unit Testing<br />“A good unit test needs both to illustrate and define the behavioral contract of the unit in question. Behavior is more than just individual methods…” – KevlinHenney<br />
    6. 6. Na’vi<br />
    7. 7. Behaviour Driven Development <br />“Is an agile software development technique that encourages collaboration between<br />Developers<br />QA<br />Business Participants<br /> in a software project.”<br />“It extends TDD by writing test cases in a <br />natural language that non-programmers can read.”<br />
    8. 8. User Stories/Features<br />Small chunks of business value.<br />Creation and priority driven by stake holders.<br />
    9. 9. Acceptance Tests/Scenarios<br />Write in the language of the business domain<br /> i.e., high-level of abstraction<br />
    10. 10. Prerequisites for executing scenarios<br />Define an interpretable language.<br />Domain Specific Language (DSL)<br />Ubiquitous language<br />Natural language<br />Choose a BDD framework<br />
    11. 11. The BDD Framework (Unit Test generation)<br />
    12. 12. Scenario description line matching example<br />Types are tagged as language contexts.<br />Each line in the file, e.g.,<br />“given a customer buys 2black jumpers”<br />Matches a member function.<br />Use double-ticked for great readability and DRYness<br />
    13. 13. State within scenarios<br />In the previous example state was changed inside the language context.<br />Contexts are created on a per scenario basis.<br />State doesn’t pass through to the next scenario<br />
    14. 14. Context Layer: Benefits of F#<br />Discriminated Unions & Active Patterns<br />Domain Modelling<br />Object Expressions<br />Implement interfaces<br />Terse syntax<br />Readability<br />Units of measure<br />Correctness<br />Double ticked method names<br />Clear & DRY<br />Async Workflows & Agents<br />Concurrency<br />
    15. 15. BDD Patterns: Templates<br />Keeping things DRY with table driven templates.<br />Useful for driving many similar test cases.<br />given a customer buys a <colour> jumper<br />and I have <x> <colour> jumpers left in stock<br />when he returns the jumper for a refund<br />then I should have <y> <colour> jumpers in stock<br />examples:<br />| x | y | colour |<br />| 1 | 2 | green |<br />| 3 | 4 | black |<br />| 5 | 6 | red |<br />
    16. 16. BDD Patterns: Tables<br />Using tables makes data input much more readable.<br />Tables are passed into functions.<br />given the following bids exist in the Cape/Panamax market<br />| qty@price | credit |<br />| 1000@ 12.9 | good |<br />| 1000@ 12.7 | bad |<br />| 800 @ 12.5 | good |<br />and the following offers exist in the Panamax market<br />| qty@price | credit |<br />| 1000@ 12.9 | good |<br />when I observe implied orders for the Cape market<br />then I should see the following bids<br />| qty@price | credit |<br />| 1000@ 0.0 | good |<br />
    17. 17. BDD Patterns: Templated Tables<br />given the following bids exist in the Cape/Panamax market<br />| qty@price | credit |<br />| 1000@ <price1> | <cred1> |<br />| 1000@ 12.7 | bad |<br />| 800 @ 12.5 | good |<br />and the following offers exist in the Panamax market<br />| qty@price | credit |<br />| 1000@ <price2> | <cred2> |<br />when I observe implied orders for the Cape market<br />then I should see the following bids<br />| qty@price | credit |<br />| 1000@ <calPrice> | <calCred> |<br />examples:<br />| price1 | price2 | calPrice | cred1 | cred2 | calCred |<br />| 1.0 | 1.0 | 0.0 | good | good | good |<br />| 1.0 | 0.0 | -1.0 | good | good | good |<br />| 2.50 | 2.50 | 0.0 | bad | good | bad |<br />
    18. 18. Representation of complex scenarios<br />Plain text is dull.<br />Rich text is cool.<br />It makes the point of the scenario pop out.<br />Tables don’t look as ugly!<br />Confluence BDD tool<br />It downloads features from a Confluence Wiki.<br />Then transforms them into executable features.<br />
    19. 19. Confluence BDD <br />
    20. 20. BDD Patterns: More<br />Lots of examples online.<br />Search for gherkin.<br />Look at<br />
    21. 21. Benefits of using BDD<br />Shared understanding of goals and progress.<br />It is independent of the implementation.<br />Use the same tests on many implementations.<br />Regression suite.<br />Nightly regression tests.<br />Reduces QA lag at the start of the project. <br />QA can start specifying behaviour straight away.<br />
    22. 22. Costs of BDD<br />Requires more interaction with stake holders.<br />Requires more development effort than not testing at all.<br />
    23. 23. Costs of not using BDD<br />Cost of wrong requirements.<br />Cost of poor design.<br />Cost of changing implementation and having to refactor all of the tests.<br />
    24. 24. The role of Unit Tests<br />Primary coverage should come from behaviour specifications.<br />Unit Tests should be used pragmatically.<br />Documentation<br />Edge cases<br />
    25. 25. BDD Frameworks<br />General<br />RSpec<br />Cucumber<br />JBehave<br />JSpec<br />etc.<br />.Net specific<br />NBehave<br />Nspec<br />Cuke4Nuke<br />SpecFlow<br />StorEvil<br />
    26. 26. SpecFlow: Integrated environment<br />
    27. 27. Case Study: Indirect Aggression Project<br />Support indirect aggression of implied prices.<br />Requires extension to C++ Library.<br />Verification is biggest problem.<br />Not suited to Unit Tests.<br />Behaviour can be tested at API.<br />F# made it easy to model the API in few lines.<br />Language interpretation was reused.<br />Starting to build up a regression suite.<br />
    28. 28. Example scenario<br />
    29. 29. Example matched function<br />
    30. 30. Further Reading<br />