Cucumber presenation

2,735 views

Published on

Cucumber presenation

  1. 1. Presented by : Ben Wafi Oussama 1
  2. 2. PLAN• 1 Introduction• 2 Defintion• 3 Gherkin• 4 Gherkin Source File• 5 Cucumber & BDD• 6-Installation• 7-Running• 8-Demo• 9-Conclusion 2
  3. 3. Introduction(1/2)• Cucumber lets software development teams describe how software should behave in plain text. The text is written in a business readable domain specific-language and serves as documentation, automated tests and development-aid - all rolled into one format.• Cucumber works with Ruby, Java, .NET, Flex or web applications written in any language. It has been translated to over 40 spoken languages. 3
  4. 4. Introduction(2/2)1: Describe behavior in plain text 2: Write a step definition in Ruby 3: Run and watch it fail 4. Write code to make the step pass 5. Run again and see the step pass 6. Repeat 2-5 until green like a cuke 4
  5. 5. Definition• Cucumber is a tool that executes plain-text functional descriptions as automated tests. The language that Cucumber understands is called Gherkin It is a Business Readable, Domain Specific Language that lets you describe software’s behavior without detailing how that behavior is implemented. 5
  6. 6. Definition• Cucumber itself is written in Ruby, but it can be used to “test” code written in Ruby or other languages including but not limited to Java, C# and Python. 6
  7. 7. Gherkin(1/3)• Gherkin serves two purposes – documentation and automated tests• Gherkin’s grammar is defined in the Treetop grammar that is part of the Cucumber codebase. The grammar exists in different flavors for many spoken languages (37 at the time of writing), so that your team can use the keywords in your own language.• Source files have .feature extension. 7
  8. 8. Gherkin Syntax(2/3)• Like Python and YAML, Gherkin is a line- oriented language that uses indentation to define structure. Line endings terminate statements (eg, steps).• Parser divides the input into features, scenarios and steps. When you run the feature the trailing portion (after the keyword) of each step is matched to a Ruby code block called Step Definitions. 8
  9. 9. Gherkin Syntax(3/3)• "en": { • "ar": {• "name": "English", • "name": "Arabic",• "native": "English", • "native": "• "feature": "Feature|Busines Need|Ability", • feature": "• "background": "Background", • background": "• "scenario": "Scenario", • scenario": "• "scenariooutline":"ScenariOutline|Scenar • scenario_outline": "• "examples": "Examples|Scenarios", • examples": "• "given": "*|Given", • given": "*|• "when": "*|When", • when": "*|• "then": "*|Then", • then": "*|• "and": "*|And", • and": "*|• "but": "*|But" • but": "*|• }, • 9
  10. 10. A Gherkin source file usually looks like this1: Feature: Some terse yet descriptive text of what is desired2: In order to realize a named business value3: As an explicit system actor4: I want to gain some beneficial outcome which furthers the goal5:6: Scenario: Some determinable business situation7: Given some precondition8: And some other precondition9: When some action by the actor10: And some other action11: And yet another action12: Then some testable outcome is achieved13: And something else we can check happens too14:15: Scenario: A different situation 10
  11. 11. • First line starts the feature.• Lines 2-4 are unparsed text, which is expected to describe the business value of this feature. Line 6 starts a scenario.• Lines 7-13 are the steps for the scenario.• Line 15 starts next scenario and so on. 11
  12. 12. .Feature• The scenario is then divided into three parts.1. The ‘Given’ part describes how the system should be prepared before the testing. This is the setup for the system.2. The ‘When’ part describes how the system should be used. This is the execution part of the example.3. The ‘Then’ part is where you verify that the system is in the expected state. This is the assert part of the test. 12
  13. 13. TDD & BDD• Test driven developmentThe word “driven” here refers to the way of writing thetests first, then the code to make the tests pass. Testdriven development is more of a developer orientedapproach, a more low level way of doing things.• Behaviour driven developmentIn BDD on the other hand, the tests are described in anatural language, which makes the tests more accessibleto people outside of development or testing teams. It candescribe the functionality as specifications do. 13
  14. 14. Cucumber and BDD• While Cucumber can be thought of as a “testing” tool, the intent of the tool is to support BDD. This means that the “tests” (plain text feature descriptions with scenarios) are typically written before anything else and verified by business analysts, domain experts, etc. non technical stakeholders. The production code is then written outside-in, to make the stories pass. 14
  15. 15. Installation(1/2)• In order to use Cucumber within some frameworks or specific environments :• install for Ruby on Rails• install for Jruby and Java• install for IronRuby and .NET 15
  16. 16. Installation(2/2) Cucumber-jvm JUnit class that will connect the feature to a runner, Cucumber-html.jar Jchronic.jarCucumber-core.jar Cucumber-java.jar Cucumber-junit.jar 16
  17. 17. Running Cucumber• There are quite a few ways you can run Cucumber. It depends on what programming language you are using and also what build tool you are using (if any).• Command Line• Rake• Maven• Ant• JUnit• IDEs (Eclipse, IDEA) 17
  18. 18. Demo ApplicationSrc/test/java Src/main/java HelloSteps.Defjava RunCukesTest.java Hello.java .features 18
  19. 19. ConclusionTry to use Cucumber 19
  20. 20. Thank You 20

×