bdd in java using cucumber

21
Slav Kurochkin Software Engineer EPIC Loan Systems Behavior-driven development in Java using Cucumber-JVM

Upload: slavkurochkin

Post on 16-Apr-2017

73 views

Category:

Internet


1 download

TRANSCRIPT

Page 1: BDD in Java using Cucumber

Slav Kurochkin Software Engineer

EPIC Loan Systems

Behavior-driven development in Java using Cucumber-JVM

Page 2: BDD in Java using Cucumber

Cucumber Overview Part I

2

Page 3: BDD in Java using Cucumber

What is Cucumber?

3

Page 4: BDD in Java using Cucumber

Cucumber is BDD tool Cucumber is NOT just a plant

4

Page 5: BDD in Java using Cucumber

A single source of truth Cucumber merges specification and test documentation into one cohesive whole.

Living documentation Because they're automatically tested by Cucumber, your specifications are always bang up-to-date.

Focus on the customer Business and IT don't always understand each other. Cucumber's executable specifications encourage closer collaboration, helping teams keep the business goal in mind at all times.

Less rework When automated testing is this much fun, teams can easily protect themselves from costly regressions.

5

Page 6: BDD in Java using Cucumber

So how Cucumber work? Business and Technology work together

6

Page 7: BDD in Java using Cucumber

What is the main components of Cucumber and how to make it grow fast?*

*There is no need for chemicals, just a bit of coding

7

Page 8: BDD in Java using Cucumber

- Feature files written in Gherkin (Given, When Then) - Step Definitions glue plain english to code using RegEx - Configuration file, helping you configure testing environment (setup, cleanup, outcome)

8

Page 9: BDD in Java using Cucumber

Feature file

• Tag - let us define execution path

• Feature - name of the the component we test

• Description - short description of what we are testing

• Background - common behavior for all scenarios

• Scenario - individual test

• Gherkin - Scenario steps (Given, When, Then)

9

Page 10: BDD in Java using Cucumber

Gherkin

• Given - defines initial state of testing application

• When - action, invoke methods, calling API, interacting with UI layer

• Then - Asserting outcome

• And - helper if Given, When, Then is not enough

10

Page 11: BDD in Java using Cucumber

Step Definition

• Sketching out the domain model

• Annotations defines given, when, then

• RegEx to glue Feature file to Java code(or whatever language you use).

11

Page 12: BDD in Java using Cucumber

Configuration file

• Test setup

• Test cleanup

• Test outcome

12

Page 13: BDD in Java using Cucumber

Cucumber Technical Details Part II

13

Page 14: BDD in Java using Cucumber

What can you test with Cucumber?

14

Page 15: BDD in Java using Cucumber

• DataBase Testing

• Unit or/and Component Testing

• API Testing using frameworks like RestAssured

• Web UI testing using Selenium WebDriver

15

Page 16: BDD in Java using Cucumber

Technical features of Cucumber

• Run specific tests (using tags)

• Rerun failed tests

• Parametrized tests (data driving tests)

• Reusable steps (steps showing up in predictive way)

• Detailed report (in case of UI testing we can add screenshot on fail)

• Configurable test 16

Page 17: BDD in Java using Cucumber

Cucumber scenario states

• Failed - scenario failed

• Pending - step definition created but there is no code implementation yet

• Undefined - there is Gherkin steps, but no step definition

• Skipped - if scenario failed theres is no need to waste time and executing rest of the steps

• Passed - lucky you :)

17

Page 18: BDD in Java using Cucumber

Scenario vs Scenario Outline

18

Page 19: BDD in Java using Cucumber

Cucumber-JVM Test Runners

• JUnit

• CLI runners (Gradle, Maven, Ant etc)

• Android runner

• Third party runners

19

Page 20: BDD in Java using Cucumber

Test Code Examples (can be found on github)

20

Page 21: BDD in Java using Cucumber

References• https://cucumber.io/docs

• http://docs.behat.org

• https://relishapp.com

• http://specflow.org/documentation/

• https://www.ibm.com/developerworks/library/a-automating-ria/

• “The Cucumber For Java Book” by Seb Rose, Matt Wynne, & Aslak Helesoy

• “Specification by Example” by Gojko Adzic

• “BDD in Action” by John Ferguson Smart

• Rest-Assured with Cucumber: Using BDD for web services automation https://angiejones.tech/rest-assured-with-cucumber-using-bdd-for-web-services-automation/ by Angie Jones

• toolsqa.com

21