behavioural driven development с java - qa testing · pdf filetest-driven development (tdd)...
TRANSCRIPT
![Page 1: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/1.jpg)
Behaviour Driven Development
with Java
Nikolay Vasilev
15 July 2011
![Page 2: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/2.jpg)
Content
What BDD is?
Jbehave
JBehave and Selenium
Jbehave – Pros and Cons
Questions and Answers
References
2
![Page 3: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/3.jpg)
BDD
3
![Page 4: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/4.jpg)
Test-Driven Development (TDD)
Approach for developing software by
writing tests before writing the code
being tested
4
Write little test
Watch test fail
Get test pass
Refactor
![Page 5: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/5.jpg)
Test-Driven Development (TDD)
Facilitates Software Design
Express Software Behaviour
Documents the Code
5
![Page 6: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/6.jpg)
Unit Testing
A form of TDD
Meets developer’s expectations for the
code behaviour
Fragile – Too coupled to the
implementation
Should meet user’s expectations
6
![Page 7: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/7.jpg)
User’s Expectations
Use Cases
User Stories
◦ preferred in Agile projects
Both of them have no validating
mechanisms that the code meets user’s
expectations
7
![Page 8: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/8.jpg)
Testing Types and Expectations
8
Application
Levels Testing Type Expectations
UI / Presentation / …
Controls / Services / …
Classes / Models / …
Code Meets
Customer’s
Expectations
Code Meets
Programmer’s
Expectations
Unit
Testing
BDD
Selenium
![Page 9: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/9.jpg)
DDD and Ubiquitous Language
Domain Driven Design
◦ Approach to developing software for complex
needs by deeply connecting the
implementation to an evolving model of the
core business concepts
Ubiquitous Language (UL)
◦ "A language structured around the domain model
and used by all team members to connect all the
activities of the team with the software" –
Domain Driven Design by Eric Evans.
9
![Page 10: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/10.jpg)
Executable Documentation
The system requirements are usually
expressed by textual documentation
◦ In the ideal world the documentation uses UL
If this documentation was executable, it
would be perfect!
It would assure that the code continues
to meet the expectations in long term
10
![Page 11: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/11.jpg)
Behaviour Driven Design
A TDD approach
It is an executable documentation
Helps for UL development and usage
Clears out the misunderstandings between customers, domain experts, developers, QA team etc.
Can be used by everybody involved in a project
11
![Page 12: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/12.jpg)
BDD as Stories and Behaviour
BDD can be used to express Stories and Behaviour
Stories
◦ Correspond to User Stories
◦ Express application behaviour at high level
◦ Stories framework needed (eventually)
Behaviour (or Spec)
◦ Corresponds to expectations at class level
◦ Expresses behaviour at service/component level
12
![Page 13: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/13.jpg)
Stories and Behaviour
User Stories
◦ Series of acceptance criteria
◦ Called scenarios
◦ Each scenario has givens, events and outcomes
◦ Used in Agile projects
Behaviour
◦ Expressed as a test method
◦ It defines what the application should / shouldn’t do
13
![Page 14: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/14.jpg)
A Story Structure
Narrative
◦ As a [some_role_here]
◦ I want [some_feature_here]
◦ So that [behefit/value_of_the_feature_here]
Scenario(s) (this is acceptance criteria)
◦ Given [some_initial_condition(s)]
◦ When [event(s)_occurs]
◦ Then [ensure_some_outcome(s)]
14
![Page 15: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/15.jpg)
BDD Process
15
Stories Behaviour Application
Exercise expectations
against Matches to
Customer QA Domain Expert Developer
![Page 16: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/16.jpg)
BDD Process
16
![Page 17: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/17.jpg)
BDD Process
Create scenarios for expected features
Then follow the process:
1. For each scenario describing a feature
2. Run the scenario – it fails (go red)
3. Define the first step – go red
4. Write down the application code getting the step to pass – go green
5. Refactor the code and repeat steps 4 & 5 for each step until 6
6. The scenario passes – go green
7. Refactor the application code
17
![Page 18: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/18.jpg)
BDD Tools
C – Cspec
C++ – CppSpec, Spec-CPP
.Net – NBehave, NSpecify, SpecFlow
Groovy – GSpec, easyb, Cuke4Duke
PHP – PHPSpec
Python – Specipy
Ruby – RSpec, Shoulda, Cucumber
More…
18
![Page 19: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/19.jpg)
BDD Tools (Java Related)
JBehave – Java annotations based, Test frameworks agnostic
Cuke4duke – Cucumber support for JVM
JDave – RSpec (Ruby) inspired, Mojo 2 & Hamcrest based
beanSpec – Java based
easyb – Java based, Specifications written in Groovy
instinct – BDD framework for Java, providing annotations for contexts. Inspired by Rspec
BDoc - Extracts behaviour from unit tests
19
![Page 20: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/20.jpg)
JBehave
20
![Page 21: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/21.jpg)
JBehave
Open Source Java-based BDD Framework
◦ Created by Dan North (2003) to compare
BDD to TDD
Current version 3.4.2
Components
◦ JBehave Main
◦ JBehave Web
21
![Page 22: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/22.jpg)
JBehave - Features
Pure Java implementation
Text-based user stories
Annotation-based binding of textual steps to Java methods
DI support (Spring, Guice, Pico, Weld)
Story reporting (HTML, TXT, XML)
User stories localization
IDE integration
Ant and Maven integration
Test frameworks agnostic (JUnit, hamcrest, etc.)
22
![Page 23: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/23.jpg)
JBehave Web - Features
Extension of JBehave providing web
integration layer for BDD
Features
◦ JBehave Queue – allows generic stories to be
run asynchronously
◦ Web Runner – allows generic stories to be
run synchronously
◦ Selenium Integration – automation of stories
for web apps using Selenium
23
![Page 24: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/24.jpg)
JBehave – Five Steps Overview
24
1. Write a story
2. Map steps to Java
3. Configure Stories
4. Run Stories
5. View Reports
![Page 25: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/25.jpg)
JBehave – Five Steps Overview
Step 1 – Write a story
25
Narrative:
In order to calculate BMI with ease
As a doctor
I want to have BMI Calculator application
Meta:
@author Nikolay Vasilev
@bg-jug
Scenario: Simple BMI calculator validation
Given a body mass index calculator
When a patient's is with mass 77 kg and height 1.75 m
Then patient's body mass index is 25.14285659790039
![Page 26: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/26.jpg)
JBehave – Five Steps Overview
Step 2 – Map steps to Java
26
![Page 27: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/27.jpg)
JBehave – Five Steps Overview
Step 3 – Configure stories
27
![Page 28: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/28.jpg)
JBehave – Five Steps Overview
Step 4 – Run stories with:
28
![Page 29: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/29.jpg)
JBehave – Five Steps Overview
Step 5 – View Reports (HTML, TXT, XML)
29
![Page 30: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/30.jpg)
JBehave – Use Case
Body Mass Index Calculator and Classifier
Domain Classes
30
![Page 31: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/31.jpg)
JBehave – Use Case
BMICalculator component
Computes BMI by the formula:
Where
◦ BMI – body mass index
◦ W – a person’s mass in kilograms
◦ h – a person’s height in meters
31
![Page 32: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/32.jpg)
JBehave – Use Case
WeightClassifier component
32
![Page 33: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/33.jpg)
JBehave Stories
Plain-text stories ◦ Consists of narrative and multiple scenarios
◦ Usually stored as .story file, but this is configurable
Narrative ◦ Optional ◦ As a, In order to, I want to
A scenario consists of: ◦ Given, When, Then
◦ And maps to any of them
◦ Possible use of When after Then ◦ Scenarios could depend on others scenario
GivenScenarios
Comments (!--)
33
![Page 34: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/34.jpg)
JBehave Steps
Declared as Java annotations
Steps annotations ◦ @Given, @When, @Then
Lifecycle annotations ◦ @BeforeStory, @AfterStory
◦ @BeforeScenario, @AfterScenario
Pending steps
◦ @Pending keyword
34
![Page 35: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/35.jpg)
JBehave Steps
Step annotations take regex
◦ See Code Example
Alias(es) – mapping various text strings to one method ◦ @Alias, @Aliases
◦ See Code Example
Parameter Injection
◦ Captured values are converted to method parameters
◦ @Named – Explicit mapping of values to parameters
◦ See Code Example
35
![Page 36: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/36.jpg)
JBehave Configuration
Everything is configurable (powerful)
Everything has defaults (makes life easy)
Main Configuration
◦ How to load stories (classpath, file, etc.)
◦ Story file naming and parsing configuration
◦ Error strategy and Pending error strategy
How to handle failure and missing steps
Step Configuration
◦ Parameter Converters
36
![Page 37: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/37.jpg)
JBehave Configuration
Embedder and Embeddable
37
![Page 38: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/38.jpg)
JBehave Configuration
Jbehave provides two Embeddable implementations ◦ ConfigurableEmbedder
◦ InjectableEmbedder (example AnnotatedEmbedder)
JUnit-enabled Embeddables
◦ Ran like JUnit tests
◦ JUnitStory - one-to-one mapping with the textual story
◦ JUnitStories - many-to-one mapping
Exntending Embedder ◦ EclipseEmbedder example
38
![Page 39: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/39.jpg)
JBehave – Advanced
Parameterized Scenarios ◦ Examples: - required in the story
◦ Followed by table of parameters
◦ The mapped parameters should be surrounded by '<‘ and '>‘ in the story
Table examples require named parameters for the step candidates to be matched to the Java methods ◦ The step annotation pattern must hold the
verbatim textual step
The tables could be loaded from external resources
39
![Page 40: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/40.jpg)
JBehave – Advanced
Non-English Keywords
Tabular parameters
◦ Multiline values
◦ Example:
40
Given tab
e|---------------------------------
B|---------------------------------
G|---------------------------------
D|----------0--0-------------------
A|-0--2--3----------2--0-----0--0–
E|------------------------3--------
When the guitar plays
Then the following notes will be played
A0 A2 A3 D0 D0 A2 A0 E3 A0 A0
![Page 41: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/41.jpg)
JBehave – Advanced
Meta information ◦ Meta
◦ Followed by name value properties separated
by @
◦ Example:
Meta filtering
◦ Used for selecting of stories
41
Meta
@author Nikolay Vasilev
@organization Bulgarian Java Users Group
-author *Vasilev
![Page 42: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/42.jpg)
JBehave – Advanced
Ant tasks and Maven plugin
Integration with Spring, Pico, Guice
Reporting options
◦ Console, Text, HTML, XML
◦ Default reports location in a Maven project: ${project.dir}/target/jbehave
◦ Example
Test integration (JUnit and TestNG)
◦ See AnnotatedEmbedder example
42
![Page 43: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/43.jpg)
JBehave Reporting Options
Reports HTML Report
43
![Page 44: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/44.jpg)
JBehave Reporting Options
Failing Story HTML Report
44
![Page 45: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/45.jpg)
JBehave Reporting Options
Pending Steps Story HTML Report
45
![Page 46: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/46.jpg)
JBehave Reporting Options
Parametrized Story HTML Report
46
![Page 47: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/47.jpg)
JBehave – Eclipse Plugin
Home Page
Status: In development
Non-trivial installation (next slides)
Not very rich functionality but makes the life easier
Provides
◦ Basic highlighting
◦ On match, the step in the story is linked to the mapped method
◦ Certain autocomplete when writing stories
47
![Page 48: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/48.jpg)
JBehave – Eclipse Plugin
Example
◦ Keywords highlighting
◦ “Jumping” from story to Steps class
◦ Autocomplete
48
![Page 49: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/49.jpg)
JBehave – Install Eclipse Plugin
1. Download the plugin
49
![Page 50: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/50.jpg)
JBehave – Install Eclipse Plugin
2. Eclipse > File > Import
50
![Page 51: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/51.jpg)
JBehave – Install Eclipse Plugin
3. Existing Projects into Workspace
51
![Page 52: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/52.jpg)
JBehave – Install Eclipse Plugin
4. Select archive file: > Browse
52
![Page 53: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/53.jpg)
JBehave – Install Eclipse Plugin
5. Select archive file > Open
53
![Page 54: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/54.jpg)
JBehave – Install Eclipse Plugin
6. Select archive file:
54
![Page 55: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/55.jpg)
JBehave – Install Eclipse Plugin
7. Finish
55
![Page 56: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/56.jpg)
JBehave – Install Eclipse Plugin
8. Project Editor > Select the new project
56
![Page 57: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/57.jpg)
JBehave – Install Eclipse Plugin
9. File > Export
57
![Page 58: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/58.jpg)
JBehave – Install Eclipse Plugin
10. Select > Deployable plug-ins and frag…
58
![Page 59: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/59.jpg)
JBehave – Install Eclipse Plugin
11. Select > Deployable plug-ins and frag…
59
![Page 60: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/60.jpg)
JBehave – Install Eclipse Plugin
12. Select the Plug-in & Chose Install into
host
60
![Page 61: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/61.jpg)
JBehave – Install Eclipse Plugin
13. Restart Eclipse (Chose ‘Yes’)
61
![Page 62: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/62.jpg)
JBehave – Install Eclipse Plugin
14. The story files are with different icon
62
![Page 63: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/63.jpg)
JBehave – Install Eclipse Plugin
15. Not “recognized” stories > Select +
Right Click > Open With > Behavior
Editor
63
![Page 64: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/64.jpg)
JBehave – Install Eclipse Plugin
16. Now the keywords are highlighted
64
![Page 65: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/65.jpg)
Jbehave and Selenium
65
![Page 66: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/66.jpg)
JBehave and Selenium
Selenium
◦ A suite of tools to automate web app testing
across many platforms.
◦ Abstracts away the interaction with the web
layer (browser/server)
66
Java, Perl,
C#, C, etc.
Selenium
Object
Tested
WebApp
Selenium RC
Server
Browsers
![Page 67: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/67.jpg)
JBehave and Selenium
Selenium would let us focus on testing the
web-app functionality
Although, steps classes get cluttered by
selenium calls
67
Steps Selenium
Object
Tested
WebApp
Selenium RC
Server Browsers
Stories
![Page 68: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/68.jpg)
JBehave and Selenium
JBehave and Selenium
◦ First thought - Steps will interact with the
selenium object from the steps classes
68
Steps Selenium
Object
Tested
WebApp
Selenium RC
Server Browsers
Stories
![Page 69: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/69.jpg)
JBehave and Selenium
Page Objects Pattern
◦ Page object represent the services offered by
a page
◦ Hides the knowledge of the page structure
from the developer
69
Steps
Selenium
Object Tested
WebApp
Selenium RC
Server Browsers Stories
Page
Object
![Page 70: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/70.jpg)
JBehave and Selenium
Rules of Thumb
◦ Keep assertions in the steps mapping classes
◦ Keep selenium interaction in the page objects
◦ Stories should address the functionality which
the pages offer
70
![Page 71: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/71.jpg)
JBehave and Selenium
What do we need to integrate JBehave
and Selenium
◦ SeleniumConfiguration (part of JBehave Web)
◦ @BeforeScenario, @AfterScenario steps
Responsible of start/stop selenium object
◦ Pages and Steps implementation
Running selenium tests in an automated
way (maven – integration-test phase)
Tip: Configure Firefox for testing with
Selenium
71
![Page 72: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/72.jpg)
Use Case – Web Testing
Web app for our Use Case
◦ 2 JSPs – one for main form, another for result
In order to run it are required:
◦ Run the web app on a web server
◦ Run the Selenium RC server with the
selenium profile (see tip from prev. slide)
◦ Execute WebBmiCalculatorStories embedder
as JUnit test
72
![Page 73: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/73.jpg)
Use Case – Web Testing
Main form
73
![Page 74: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/74.jpg)
Use Case – Web Testing
Result page
74
![Page 75: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/75.jpg)
Use Case – Web Testing
The main form is also error page
75
![Page 76: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/76.jpg)
JBehave - Pros and Cons
76
![Page 77: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/77.jpg)
Questions and Answers
77
![Page 78: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/78.jpg)
Use Case & Examples Code
Use Case Code –
◦ Consists of 3 Maven 2 projects
jug-bg-bdd-domain
◦ Domain Classes of the Application jug-bg-bdd-jbehave
◦ JBehave Examples (depending on the first project)
jug-bg-bdd-web
◦ JBehave & Selenium Examples (depending on the first project)
78
![Page 79: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/79.jpg)
Use Case & Examples Code
Source Code could be found on:
http://code.google.com/p/bg-jug-resource-
repository/
79
![Page 80: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/80.jpg)
References
BDD Wiki
Jbehave
JBehave Tutorial
Dan North – Introducing BDD
Dan North - What’s in a Story?
[pdf] BDD in Java and Groovy
[pdf] TDD Beyond Junit
BDD in a Nutshell
80
![Page 81: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/81.jpg)
References
Ryan Greenhall – BDD by Example
Localizing JBehave Scenarios
Eric Evans - "Domain-Driven Design:
Tackling Complexity in the Heart of
Software", Addison-Wesley
JBehave Site :: Dependency Injection
JBehave + Spring + Selenium Example
81
![Page 82: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/82.jpg)
References
Selenium Project
Page Objects Pattern
Creating Firefox Profile for Selenium RC
Tests
JBehave Site :: Using Selenium
BDD with JBehave Web 3, Selenium and
Maven 2 for OS X Leopard
Nice JBehave + Selenium + Maven Example
Selenium Tutorial to set up a Selenium Grid
82
![Page 83: Behavioural Driven Development с Java - QA Testing · PDF fileTest-Driven Development (TDD) ... implementation to an evolving model of the core business concepts ... Selenium Object](https://reader031.vdocuments.mx/reader031/viewer/2022022500/5aa1b3277f8b9a436d8bf500/html5/thumbnails/83.jpg)
Thank you for your attention!
83