This document provides an introduction to Behaviour Driven Development (BDD). It discusses that BDD aims to bridge communication gaps between developers and clients by using examples written in a common language. It also provides a practical example of setting up BDD with JBehave and Java in IntelliJ IDEA, including creating a story file, steps class, and linking class. The document demonstrates how BDD allows describing desired system behaviors in a way that is understandable to both technical and non-technical stakeholders.
Test and Behaviour Driven Development (TDD/BDD)Lars Thorup
In this introduction to Test Driven Development (TDD) or Behaviour Driven Development (BDD) we give a high level description of what it is and why it is useful for developers. Then we go into some details on stubs and mocks, test data, UI testing, SQL testing, JavaScript testing, web services testing and how to start doing TDD/BDD on an existing code base.
This presentation introduces the audience to BDD - the Behavior-Driven Development method and how it can be applied to development and testing of GUI applications. We will also try to debunk myths and false hopes surrounding it.
BDD centers around stories written in an "ubiquitous language" that describe the expected behavior of an application. The use of a human-readable language allows for technical as well as non-technical project stakeholders to participate in authoring of feature descriptions. Those descriptions then serve as a base for the work of both developers and testers.
Classic agile and test-driven programming takes an inside-out approach by focussing on the specification and testing of the API of individual software components. BDD, on the other hand, looks at the application as a whole and puts interaction sequences and their expected outcomes into the foreground.
An introduction to the de-facto standard BDD language Gherkin will be given. It became popular as part of the Cucumber Ruby testing framework but has found its way into various free and commercial tools that will be listed.
A sample feature file including scenarios, outlines and backgrounds descriptions will be developed live using the Squish GUI Tester. This feature file can already be "run" in dry mode. We'll see different types of usage of this input:
* A mean to communicate with the customer.
* Documentation for the acceptance test before delivery
* A sequence to walk through for manual testing
* Automated GUI testing through tools like Squish.
PHPConf.asia 2016 - BDD with Behat for BeginnersAdam Englander
Learn the basics of Behavioral Driven Development (BDD) with Behat to build quality applications. Behat utilizes natural language syntax to define feature test scenarios. In this tutorial you will learn how to write integration tests for web applications. This will include utilizing Selenium WebDriver for real world multi-browser testing including introductions to Selenium Grid and Sauce Labs. Learn a better way to perform integration testing today!
Test and Behaviour Driven Development (TDD/BDD)Lars Thorup
In this introduction to Test Driven Development (TDD) or Behaviour Driven Development (BDD) we give a high level description of what it is and why it is useful for developers. Then we go into some details on stubs and mocks, test data, UI testing, SQL testing, JavaScript testing, web services testing and how to start doing TDD/BDD on an existing code base.
This presentation introduces the audience to BDD - the Behavior-Driven Development method and how it can be applied to development and testing of GUI applications. We will also try to debunk myths and false hopes surrounding it.
BDD centers around stories written in an "ubiquitous language" that describe the expected behavior of an application. The use of a human-readable language allows for technical as well as non-technical project stakeholders to participate in authoring of feature descriptions. Those descriptions then serve as a base for the work of both developers and testers.
Classic agile and test-driven programming takes an inside-out approach by focussing on the specification and testing of the API of individual software components. BDD, on the other hand, looks at the application as a whole and puts interaction sequences and their expected outcomes into the foreground.
An introduction to the de-facto standard BDD language Gherkin will be given. It became popular as part of the Cucumber Ruby testing framework but has found its way into various free and commercial tools that will be listed.
A sample feature file including scenarios, outlines and backgrounds descriptions will be developed live using the Squish GUI Tester. This feature file can already be "run" in dry mode. We'll see different types of usage of this input:
* A mean to communicate with the customer.
* Documentation for the acceptance test before delivery
* A sequence to walk through for manual testing
* Automated GUI testing through tools like Squish.
PHPConf.asia 2016 - BDD with Behat for BeginnersAdam Englander
Learn the basics of Behavioral Driven Development (BDD) with Behat to build quality applications. Behat utilizes natural language syntax to define feature test scenarios. In this tutorial you will learn how to write integration tests for web applications. This will include utilizing Selenium WebDriver for real world multi-browser testing including introductions to Selenium Grid and Sauce Labs. Learn a better way to perform integration testing today!
Most projects in CF now involve creating some type of consumable CFC Endpoint or API Service... do you Unit test your API, do you use Integration Tests on your API? How many ways do you test your API? Not all tests are created equal.
Description
Most projects in CF now involve creating some type of consumable CFC Endpoint or API Service... do you Unit test your API, do you use Integration Tests on your API? How many ways do you test your API? Not all tests are created equal.
We build our CFCs and CF API to be consumed with CF Apps, Mobile Apps, Javascript apps and devices we haven’t even thought about yet. To be smart developers we need to be able to test our CFC endpoints, and the code that uses those endpoints.
We’ll learn how to test your API serverside with Testbox and Clientside with Jasmine.
With Testbox and Jasmine both using BDD, your test code can almost be isomorphic.
Attendees should have some exposure to CFCs as endpoints, or CF API creations, and consuming with other languages/devices, in this case, JavaScript.
## Attendees will learn
How to use Testbox to test your CFCs 2 different ways
Different types and ways to test JavaScript
Overview of client/server side testing tools
Building testing into your workflow
You are one of many that are not testing your APIs thoroughly
Practical tips for dealing with projects involving legacy code. Covers investigating past projects, static analysis of existing code, and methods for changing legacy code.
Presented at PHP Benelux '10
Bridging the communication Gap & Continuous Deliverymasoodjan
This is a case study of a top retailer in UK which was following Agile but not all the Agile practices. We will discuss how collaboration between business and engineering team improved using BDD and how it was used to generate automated acceptance tests. We will also discuss how continuous integration was implemented which laid foundation for continuous delivery.
TDD is now mainstream but a lot people don't know or don't remember what is its purpose. TDD is about software design not testing or catching bug. TDD helps developers to shape and create software with "good" design, what is a "good" design is something that we will discuss in the topic.
Why Your Test Suite Sucks - PHPCon PL 2015CiaranMcNulty
Many teams adopt TDD attracted by the promise of a more productive workflow, fewer regressions and higher code quality. Sometimes this goes wrong and these benefits do not materialise, despite a healthy-seeming test suite. In this talk we will look at what the common pitfalls of testing are, why teams fall into these traps, and they can dig themselves out.
Unit testing and test-driven development are practices that makes it easy and efficient to create well-structured and well-working code. However, many software projects didn't create unit tests from the beginning.
In this presentation I will show a test automation strategy that works well for legacy code, and how to implement such a strategy on a project. The strategy focuses on characterization tests and refactoring, and the slides contain a detailed example of how to carry through a major refactoring in many tiny steps
The past years, a number of new database systems have appeared, like MongoDB and Redis. Most of them have radically new ways to look at data persistance, where efficient replication is prioritized over advanced query support.
In this talk we will discuss some of the benefits and drawbacks of the new key/value stores and document databases. As an example, we will demonstrate Redis, an advanced key/value store. Redis is different from most other key/value stores on two dimensions: It runs entirely in RAM and it supports a number of advanced data structures with accompanying specialized algorithms.
Most projects in CF now involve creating some type of consumable CFC Endpoint or API Service... do you Unit test your API, do you use Integration Tests on your API? How many ways do you test your API? Not all tests are created equal.
Description
Most projects in CF now involve creating some type of consumable CFC Endpoint or API Service... do you Unit test your API, do you use Integration Tests on your API? How many ways do you test your API? Not all tests are created equal.
We build our CFCs and CF API to be consumed with CF Apps, Mobile Apps, Javascript apps and devices we haven’t even thought about yet. To be smart developers we need to be able to test our CFC endpoints, and the code that uses those endpoints.
We’ll learn how to test your API serverside with Testbox and Clientside with Jasmine.
With Testbox and Jasmine both using BDD, your test code can almost be isomorphic.
Attendees should have some exposure to CFCs as endpoints, or CF API creations, and consuming with other languages/devices, in this case, JavaScript.
## Attendees will learn
How to use Testbox to test your CFCs 2 different ways
Different types and ways to test JavaScript
Overview of client/server side testing tools
Building testing into your workflow
You are one of many that are not testing your APIs thoroughly
Practical tips for dealing with projects involving legacy code. Covers investigating past projects, static analysis of existing code, and methods for changing legacy code.
Presented at PHP Benelux '10
Bridging the communication Gap & Continuous Deliverymasoodjan
This is a case study of a top retailer in UK which was following Agile but not all the Agile practices. We will discuss how collaboration between business and engineering team improved using BDD and how it was used to generate automated acceptance tests. We will also discuss how continuous integration was implemented which laid foundation for continuous delivery.
TDD is now mainstream but a lot people don't know or don't remember what is its purpose. TDD is about software design not testing or catching bug. TDD helps developers to shape and create software with "good" design, what is a "good" design is something that we will discuss in the topic.
Why Your Test Suite Sucks - PHPCon PL 2015CiaranMcNulty
Many teams adopt TDD attracted by the promise of a more productive workflow, fewer regressions and higher code quality. Sometimes this goes wrong and these benefits do not materialise, despite a healthy-seeming test suite. In this talk we will look at what the common pitfalls of testing are, why teams fall into these traps, and they can dig themselves out.
Unit testing and test-driven development are practices that makes it easy and efficient to create well-structured and well-working code. However, many software projects didn't create unit tests from the beginning.
In this presentation I will show a test automation strategy that works well for legacy code, and how to implement such a strategy on a project. The strategy focuses on characterization tests and refactoring, and the slides contain a detailed example of how to carry through a major refactoring in many tiny steps
The past years, a number of new database systems have appeared, like MongoDB and Redis. Most of them have radically new ways to look at data persistance, where efficient replication is prioritized over advanced query support.
In this talk we will discuss some of the benefits and drawbacks of the new key/value stores and document databases. As an example, we will demonstrate Redis, an advanced key/value store. Redis is different from most other key/value stores on two dimensions: It runs entirely in RAM and it supports a number of advanced data structures with accompanying specialized algorithms.
Test-Driven Developments are Inefficient; Behavior-Driven Developments are a ...Abdelkrim Boujraf
In summary, we have presented here a method for efficiently testing large parts of web-based software by using elements of code generation to generate automatable tests, and by using BDD concepts to model tests for non-generated screens and non-generated business actions. Further, we have described a method for context-based unit
testing that, when combined with generated code and tests, yields an acceptable trade-off between development efficiency and time spent on testing
In questa sessione verranno analizzate alcune pagine ASP.NET che verranno sottoposte a refactoring per aumentarne la modularità e comprensibilità del codice, nonchè favorire la testabilità delle funzioni core.
Si presenteranno techiche e strumenti che è possibile utilizzare in modo da avere un approccio più razionale ed 'ordinato' nella stesura del codice. Le pratiche ed i concetti illustrati sono di carattere generale, quindi liberamente applicabili ad ogni tipologia di applicazione.
We continue checking Microsoft projects: analysis of PowerShellPVS-Studio
It has become a "good tradition" for Microsoft to make their products open-source: CoreFX, .Net Compiler Platform (Roslyn), Code Contracts, MSBuild, and other projects. For us, the developers of PVS-Studio analyzer, it's an opportunity to check well-known projects, tell people (including the project authors themselves) about the bugs we find, and additionally test our analyzer. Today we are going to talk about the errors found in another project by Microsoft, PowerShell.
An introduction to Test-First Behavior-Driven Development, and acceptance testing with Gherkin, with some real-life Gherkin examples. Content created for C# code, but the principles do apply to other languages/environments.
Similar to Introduction to Behavior Driven Development (20)
Essentials of Automations: Optimizing FME Workflows with ParametersSafe Software
Are you looking to streamline your workflows and boost your projects’ efficiency? Do you find yourself searching for ways to add flexibility and control over your FME workflows? If so, you’re in the right place.
Join us for an insightful dive into the world of FME parameters, a critical element in optimizing workflow efficiency. This webinar marks the beginning of our three-part “Essentials of Automation” series. This first webinar is designed to equip you with the knowledge and skills to utilize parameters effectively: enhancing the flexibility, maintainability, and user control of your FME projects.
Here’s what you’ll gain:
- Essentials of FME Parameters: Understand the pivotal role of parameters, including Reader/Writer, Transformer, User, and FME Flow categories. Discover how they are the key to unlocking automation and optimization within your workflows.
- Practical Applications in FME Form: Delve into key user parameter types including choice, connections, and file URLs. Allow users to control how a workflow runs, making your workflows more reusable. Learn to import values and deliver the best user experience for your workflows while enhancing accuracy.
- Optimization Strategies in FME Flow: Explore the creation and strategic deployment of parameters in FME Flow, including the use of deployment and geometry parameters, to maximize workflow efficiency.
- Pro Tips for Success: Gain insights on parameterizing connections and leveraging new features like Conditional Visibility for clarity and simplicity.
We’ll wrap up with a glimpse into future webinars, followed by a Q&A session to address your specific questions surrounding this topic.
Don’t miss this opportunity to elevate your FME expertise and drive your projects to new heights of efficiency.
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Albert Hoitingh
In this session I delve into the encryption technology used in Microsoft 365 and Microsoft Purview. Including the concepts of Customer Key and Double Key Encryption.
Builder.ai Founder Sachin Dev Duggal's Strategic Approach to Create an Innova...Ramesh Iyer
In today's fast-changing business world, Companies that adapt and embrace new ideas often need help to keep up with the competition. However, fostering a culture of innovation takes much work. It takes vision, leadership and willingness to take risks in the right proportion. Sachin Dev Duggal, co-founder of Builder.ai, has perfected the art of this balance, creating a company culture where creativity and growth are nurtured at each stage.
Neuro-symbolic is not enough, we need neuro-*semantic*Frank van Harmelen
Neuro-symbolic (NeSy) AI is on the rise. However, simply machine learning on just any symbolic structure is not sufficient to really harvest the gains of NeSy. These will only be gained when the symbolic structures have an actual semantics. I give an operational definition of semantics as “predictable inference”.
All of this illustrated with link prediction over knowledge graphs, but the argument is general.
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Jeffrey Haguewood
Sidekick Solutions uses Bonterra Impact Management (fka Social Solutions Apricot) and automation solutions to integrate data for business workflows.
We believe integration and automation are essential to user experience and the promise of efficient work through technology. Automation is the critical ingredient to realizing that full vision. We develop integration products and services for Bonterra Case Management software to support the deployment of automations for a variety of use cases.
This video focuses on the notifications, alerts, and approval requests using Slack for Bonterra Impact Management. The solutions covered in this webinar can also be deployed for Microsoft Teams.
Interested in deploying notification automations for Bonterra Impact Management? Contact us at sales@sidekicksolutionsllc.com to discuss next steps.
Transcript: Selling digital books in 2024: Insights from industry leaders - T...BookNet Canada
The publishing industry has been selling digital audiobooks and ebooks for over a decade and has found its groove. What’s changed? What has stayed the same? Where do we go from here? Join a group of leading sales peers from across the industry for a conversation about the lessons learned since the popularization of digital books, best practices, digital book supply chain management, and more.
Link to video recording: https://bnctechforum.ca/sessions/selling-digital-books-in-2024-insights-from-industry-leaders/
Presented by BookNet Canada on May 28, 2024, with support from the Department of Canadian Heritage.
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...DanBrown980551
Do you want to learn how to model and simulate an electrical network from scratch in under an hour?
Then welcome to this PowSyBl workshop, hosted by Rte, the French Transmission System Operator (TSO)!
During the webinar, you will discover the PowSyBl ecosystem as well as handle and study an electrical network through an interactive Python notebook.
PowSyBl is an open source project hosted by LF Energy, which offers a comprehensive set of features for electrical grid modelling and simulation. Among other advanced features, PowSyBl provides:
- A fully editable and extendable library for grid component modelling;
- Visualization tools to display your network;
- Grid simulation tools, such as power flows, security analyses (with or without remedial actions) and sensitivity analyses;
The framework is mostly written in Java, with a Python binding so that Python developers can access PowSyBl functionalities as well.
What you will learn during the webinar:
- For beginners: discover PowSyBl's functionalities through a quick general presentation and the notebook, without needing any expert coding skills;
- For advanced developers: master the skills to efficiently apply PowSyBl functionalities to your real-world scenarios.
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...UiPathCommunity
💥 Speed, accuracy, and scaling – discover the superpowers of GenAI in action with UiPath Document Understanding and Communications Mining™:
See how to accelerate model training and optimize model performance with active learning
Learn about the latest enhancements to out-of-the-box document processing – with little to no training required
Get an exclusive demo of the new family of UiPath LLMs – GenAI models specialized for processing different types of documents and messages
This is a hands-on session specifically designed for automation developers and AI enthusiasts seeking to enhance their knowledge in leveraging the latest intelligent document processing capabilities offered by UiPath.
Speakers:
👨🏫 Andras Palfi, Senior Product Manager, UiPath
👩🏫 Lenka Dulovicova, Product Program Manager, UiPath
UiPath Test Automation using UiPath Test Suite series, part 4DianaGray10
Welcome to UiPath Test Automation using UiPath Test Suite series part 4. In this session, we will cover Test Manager overview along with SAP heatmap.
The UiPath Test Manager overview with SAP heatmap webinar offers a concise yet comprehensive exploration of the role of a Test Manager within SAP environments, coupled with the utilization of heatmaps for effective testing strategies.
Participants will gain insights into the responsibilities, challenges, and best practices associated with test management in SAP projects. Additionally, the webinar delves into the significance of heatmaps as a visual aid for identifying testing priorities, areas of risk, and resource allocation within SAP landscapes. Through this session, attendees can expect to enhance their understanding of test management principles while learning practical approaches to optimize testing processes in SAP environments using heatmap visualization techniques
What will you get from this session?
1. Insights into SAP testing best practices
2. Heatmap utilization for testing
3. Optimization of testing processes
4. Demo
Topics covered:
Execution from the test manager
Orchestrator execution result
Defect reporting
SAP heatmap example with demo
Speaker:
Deepak Rai, Automation Practice Lead, Boundaryless Group and UiPath MVP
Generating a custom Ruby SDK for your web service or Rails API using Smithyg2nightmarescribd
Have you ever wanted a Ruby client API to communicate with your web service? Smithy is a protocol-agnostic language for defining services and SDKs. Smithy Ruby is an implementation of Smithy that generates a Ruby SDK using a Smithy model. In this talk, we will explore Smithy and Smithy Ruby to learn how to generate custom feature-rich SDKs that can communicate with any web service, such as a Rails JSON API.
Generating a custom Ruby SDK for your web service or Rails API using Smithy
Introduction to Behavior Driven Development
1. An introduction to Behaviour Driven Development
Richard Oellermann - 04305213
Robin O'Brien - 28097069
Vlastimir Obradovich - 28429444
2. Introduction
Ever since the dawn of software development, there is a
communication and knowledge gap between the
developers and their clients.
The knowledge gap cannot be helped, as we all are human
and cannot know about everything, but the communication
gap can be bridged, by providing a specification-based
testing solution, that is written in a language that both the
clients and the developers can understand.
3. Introduction (Cont.)
It is the responsibility of a professional software engineer to
write quality code, this means knowing the code is tested
and that that the code does what it should and delivers
business-value to the client, who wants quality products.
This does not however mean that this testing approach is
just meant for the closed-source world: In a large and
distributed open-source product, it is key to know that every
unit and component of code is tested. How does one
facilitate communication among developers that are
distributed and from different countries and have learnt
different coding styles?
4. Introduction (Cont.)
This project takes a look at how to make acceptance and
unit-testing in non co-located software development easier
with Behaviour Driven Development (BDD) using social
networks to communicate the acceptance and user tests.
We also look at version controlled "Stories" to aid
communication and productivity.
5. What is BDD?
BBD evolved out of Test-driven development (TDD), simply
due to developers not knowing what to test, how far to test,
what to call their tests, or why a test failed. The client, or
product owner, cannot help them, because in most cases
he does not understand the code developers are trying to
write or the product owner’s response is too vague to
determine what to test.
6. What is BDD? (Cont.)
Additionally, it was found that 3 of the “big wins” of TDD
often went unrealized by novice practitioners, namely:
3.The developer can discover the API to their code from the
tests
4.TDD’s goal is defining behavior rather than testing
5.The behavior of a system is the interaction between its
components, whereby mocking becomes essential.
7. What is BDD? (Cont.)
BDD focuses development on prioritized, business-
verifiable products through the use of a common
vocabulary between business and developers.
The bridging of the knowledge gap is accomplished by
minimizing difficulties between specification, design,
implementation and testing. Ambiguity and
miscommunication are avoided by utilizing this concise
vocabulary.
BDD is not a radical new approach to software engineering
but rather a restatement and unification of existing good
practices with a common language under one umbrella.
8. Why is it useful?
BDD helps the developers and the product
owners in the following ways:
• Test method names should be sentences
o
Helps the developers with some of their documentation
o
Helps the client, because the method names are in their
language and the documentation made sense to
business users, analysts and testers.
9. Why is it useful? (Cont.)
A simple sentence template keeps test method
focused
o
This helps the developers to write focused test methods
for the current class. If one is writing a test whose name
does not fit the template, then it means refactoring the
behavior of the method to a different class, or creating a
new class altogether.
10. Why is it useful? (Cont.)
An expressive test name is helpful when a test
fails
o
Helps the developer understand why a test is failing by
just reading the test method name. In an agile project,
test may become absolute, because the premise of the
system may change and thus a few test may be failing.
A descriptive method name can also indicate an
absolute test and requires to be deleted.
11. Why is it useful? (Cont.)
Rather think of describing the behaviour of the
system than just “testing” it.
o
This helps the developers describe, in code, the
behavior of the system before and after the unit or
component being tested. If the methods cannot describe
the behavior of the system, then they are just pushing
you in a false sense of security.
12. Why is it useful? (Cont.)
• Determining the next most important
behaviour
o
Developers can prioritize expected behaviours of a
system according to the business value of the methods
to be tested. This solves another TDD question: “Where
to start?”
o
Clients can take the written up tests, that are written in
their language, and argue what methods are still
missing or if this is really the expected behaviour of the
system.
13. Why is it useful? (Cont.)
• Requirements are behaviours too
o
This helps the developers write down the acceptance
test of the system in the format that they understand,
that the test-application can understand and that the
product-owner can understand and sign-off.
14. Practical Example
In this section, we will guide you through setting
up an IDE for BDD as well as run through a
small example of BDD using jBehave and Java
15. What will we need?
The following items are needed in order to begin with BDD.
• jbehave-web-distribution-3.4.3-bin.zip - http://jbehave.org/download.html
(download the stable Web binaries version)
• ideaIC-11.0.1.exe - http://www.jetbrains.com/idea/download/index.html
(download the Community edition)
• junit4.10.zip - https://github.com/KentBeck/junit/downloads (download the
latest version)
• IntelliJBehave_10658.zip - http://plugins.intellij.net/plugin/?idea&id=6629
(download the latest version)
16. Take Note:
Please note, that for this tutorial we will be
using IntelliJ IDEA, however please feel free to
use any IDE you feel comfortable with. Various
plugins may be required depending on your
IDE
17. Setting up the IDE and
Libraries
First things first, install IntelliJ IDEA. This is not complicated
step so we will not go into detail regarding this step.
Once you have successfully install the IDE, extract the
jbehave archive as well as the junit archive.
The final step before we launch IntelliJ is to install the
jBehave plugin. Extract the intellijbehave archive and copy
the contents of the ‘lib’ directory into the lib directory
located inside your IntelliJ install location.
18. Setting up the IDE and
Libraries (Cont.)
Next, start up IntelliJ IDEA and create a new project
• FIle > New Project
• Create a new project from scratch
• Fill in all the details needed. (For this tutorial we will be
using “vehicleSimulator” as the name of the project, and
the type as “Java Module”)
• Create a source directory
• Do not select “Groovy”
19. Setting up the IDE and
Libraries (Cont.)
We are almost ready to begin with the coding section of this
tutorial but before we begin with that we need to add the
last of the libraries.
• In your project navigation panel on the left, right click on
the first child node under “External Libraries.” In our case
we have <1.6> as we are using Sun’s JDK 1.6
• Click on “Open Library Settings”
20. Setting up the IDE and
Libraries (Cont.)
• Click on “SDK’s” (Under platform settings)
• Click “Add”
• Navigate to the folder in which you extracted the jBehave
archive.
• Then navigate to the “lib” folder and add all the “.jar” files.
(There may be more than we need)
• Finally do the same for the jUnit archive. (Simply add
jUnit-x.xx.jar)
21. Setting up the IDE and
Libraries (Cont.)
So that wraps up the initial setting up of an IDE
and project. We are now ready to begin coding
using BDD with jBehave.
22. The Code: .story
The code parts of jBehave are split into 3 separate files.
The first part we will look at is the textual story. This part is
a very important part of BDD. It is used to foster better
communication amongst various stakeholders. As we can
see, the textual story is readable by parties that may not be
able to understand code.
23. The Code: .story
The story we will be using is as follows and is saved in a
text file named: breaking_simulation.story
Scenario: We want to test the breaks on a vehicle
Given A vehicle travelling at 70 km/h
When The brakes are applied
Then The vehicle must have slowed down
24. The Code: .story
As we can see the story is broken down into different parts.
What is given, what must happen and what the results of
this action are. The last line should fail if the code we will
write does not result in the expected behaviour.
25. The Code: Steps
The next document is the steps that link code to the above
story. jBehave annotations are used to match up regex
expressions with the plaintext story file.
The steps file will be a java file named:
breakingSimulationSteps.java
26. The Code: Steps
public class breakingSimulationSteps {
private Vehicle vehicle;
private int speed;
@Given("A vehicle travelling at $speed km/h")
public void givenAVehicleAtASpeed(int speed) {
vehicle = new Vehicle(speed);
this.speed = speed;
}
@When("The brakes are applied")
public void applyTheBreaks() {
vehicle.applyBreaks();
}
@Then("The vehicle must have slowed down")
public void theVehcileShouldBeSlower() {
assertThat(vehicle.getSpeed(), lessThan(speed));
}
}
27. The Code: Steps
As we can see, it is important to make sure the content of
the annotations parameter is identical to the statement in
the story. The only exception to this is when passing values
from the story to the code as done in the @Given section of
the above example.
28. The Code: Linking the two
The last class we need is a way of linking the stories to the
jbehave executor. For this we have the following class. It is
important to note that the name needs match the .story files
name.
So in our case the following class will be called:
BreakingSimulation.java
29. The Code: Linking the two
public class BreakingSimulation extends JUnitStory {
@Override
public Configuration configuration() {
return new MostUsefulConfiguration()
// where to find the stories
.useStoryLoader(new LoadFromClasspath(this.getClass()))
// CONSOLE and TXT reporting
.useStoryReporterBuilder(new StoryReporterBuilder().withDefaultFormats().withFormats(Format.CONSOLE,
Format.TXT));
}
// Here we specify the steps classes
@Override
public InjectableStepsFactory stepsFactory() {
return new InstanceStepsFactory(configuration(), new breakingSimulationSteps());
}
}
Not the most important line in this class is the last line where we link it to the steps java class we defined earlier.
30. Conclusion
As we can see above, it is fairly easy to get started with
jBehave and BDD. Once the 3 parts have been created,
one can simply run them as normal jUnit test files.
Following a BDD method, the above files should be created
before all the implementation of the main program has
been done. As one continues to implement the main
program, the defined scenarios will begin to succeed.
31. Conclusion cont...
In a project, sub-versioning is important, for stories too, as
many developers or even the client may change the story
at any time and having the newest version available is
critical, as the behavior may have changed in the newest
version. Follow this link to see an example:
http://code.google.com/p/open-source-synergy-behaviour-driven-development
32. Give it a try!
If you want to learn more about BDD or have a
hands on experience of BDD or even just want
to connect with like minded individuals, head
over to our Facebook page:
http://www.facebook.com/OpenSourceSynergy