bdd in java using cucumber

Post on 16-Apr-2017

75 Views

Category:

Internet

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

Slav Kurochkin Software Engineer

EPIC Loan Systems

Behavior-driven development in Java using Cucumber-JVM

Cucumber Overview Part I

2

What is Cucumber?

3

Cucumber is BDD tool Cucumber is NOT just a plant

4

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

So how Cucumber work? Business and Technology work together

6

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

- 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

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

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

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

Configuration file

• Test setup

• Test cleanup

• Test outcome

12

Cucumber Technical Details Part II

13

What can you test with Cucumber?

14

• DataBase Testing

• Unit or/and Component Testing

• API Testing using frameworks like RestAssured

• Web UI testing using Selenium WebDriver

15

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

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

Scenario vs Scenario Outline

18

Cucumber-JVM Test Runners

• JUnit

• CLI runners (Gradle, Maven, Ant etc)

• Android runner

• Third party runners

19

Test Code Examples (can be found on github)

20

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

top related