1. SpecFlow ‘functional testing made easy’Twitter: @stack72Email: public@paulstack.co.ukBlog: http://paulstack.co.uk/blog
2. Agenda A look at ‘traditional testing’ Introduction to BDD ‘Testing Pyramid’ BDD Tools Introduction to WatiN The Marriage of SpecFlow and WatiN
3. Traditional Testing Ethos Kent Beck introduced us to what testing should be in late 1990’s It was the first real indication that testing should be part of the software development lifecycle Unit Tests smallest testable part of an application - e.g. method or function programmer writes as many tests as they can think of that might "break" the code every piece of code that is written will have tests for it Acceptance Tests can be broken down to smoke tests, user acceptance tests and integration tests verify that requirements as understood by developers satisfy the customers requirements This led to practices like TDD
4. What is TDD? Write a test beforewriting the production code Make a minimal change to the production code to make the test pass Refactor the code to make it better Advantages Provides a form of documentation Also provides a safety net when code changes Questions? Where do we start? What is a good enough test? How does this relate to the user stories?
6. How should these change? March 2006 – Dan North (@Tastapod) he discusses he had a problem with traditional TDD and that he ran into the same problems all other developers ran into - where to start, what to test and what not to test he decided to represent TDD in a way to avoid the pitfalls and get straight to the good stuff The article was called – “Introducing BDD”
7. BDD Key points Test method names should be sentences A simple sentence template keeps test methods focused An expressive test name is helpful when a test fails “Behaviour” is a more useful word than “test” Requirements are behaviour BDD provides a “ubiquitous language” for analysis (GWT) Acceptance criteria should be executable
14. What is SpecFlow? SpecFlow is a .Net tool that lets you write specifications / user stories in plain readable Gherkin format It integrates with Visual Studio, which means you get File->New templates for creating new feature files Gives VS debugger support, so you can set breakpoints on Given/When/Then lines in your .feature files and step through their execution When you compile a project containing SpecFlow feature files, the output is an NUnit test assembly, so you can use your favourite NUnit-compatible test runner or existing CI infrastructure to run the specifications with no additional configuration.
15. SpecFlow basically turns this type of business level detail: General rules for entering leader boards Usernames need to be checked for profanities before publication. Users will always be asked to post their scores to the leader boards, they won't be done automatically. A user has to complete at least one question correctly to be eligible to be added to the leader board. Users who don't post their scores to the leader board will not appear in any of the leader board stats. A user cannot post their score to the leader board without logging in or registering. Even if a user hasn't submitted their score to the leader board, show them where they would be positioned in the leader board, when they view it.
16. Into this level of breakdown: Given a user wants to post their score to a leader board When they have registered the nickname ‘knobhead’ Then that nickname fails the profanity test Given a user wants to post their score to a leader board When they have registered the nickname ‘QuizStar’ Then that nickname passes the profanity test
17. General rules for entering leader boards Usernames need to be checked for profanities before publication. Users will always be asked to post their scores to the leader boards, they won't be done automatically. A user has to complete at least one question correctly to be eligible to be added to the leader board. Users who don't post their scores to the leader board will not appear in any of the leader board stats. A user cannot post their score to the leader board without logging in or registering. Even if a user hasn't submitted their score to the leader board, show them where they would be positioned in the leader board, when they view it.
18. Given a user finishes a quiz When the user is not logged in Then the user is offered the chance to enter the leader board And the post to leader board button redirects to login page Given a user finishes a quiz When the user is logged in Then the user is offered the chance to enter the leader board And the post to leader board button returns successful entry
21. What is WatiN? Open source API (watin.org) that actually uses the browser for testing NOT emulating it Integrates with Visual Studio so tests can be debugged The most impressive feature of WatiN is the level of access you have to the DOM. Web tests are able to find elements by id, index, name, text, CSS class, etc., iterate through collections of elements, and invoke any event.
22. Front End Testing – Good Practice? Everything should be tested BUT we need to remember a few things when testing the UI UI tests: Can be brittle Can take time Should not replace unit and integration tests Should not be taken as 100% gospel truth
24. Summary We have looked at: Traditional testing ethos Emergence of BDD SpecFlow as a BDD tool WatiN as a testing tool SpecFlow + WatiN – Marriage made in heaven