This was my talk in Rubyconf Brazil 2016, it summarises some of my experience using BDD to improve team interaction and communication in local and distributed teams, what are the differences, what benefits I found and how I used it.
I mainly focus in BDD as a communication tool, the automated tests are only a very good side effect, but I've already used it without test automation too.
6. Ok, but how’s that going to help design
software?
• Business value is the key
• What is the next important thing the system does not do
yet?
• Use the business language to specify the software
• Use the business language to test the software
• Use the business language to write the software
• Use the business language to validate the software
7.
8. User Stories!!
•As a …
•I want to ...
•So that ...
•AS A BANK CLIENT
•I WANT TO USE THE
CASH MACHINE
•SO THAT I CAN TAKE
MONEY FROM MY
ACCOUNT
11. Behaviour Specification
• Context
• Actions
• Verification
•GIVEN THERE IS MONEY IN MY ACCOUNT
•AND I HAVE A VALID CARD
•AND THE MONEY DISPENSER HAS MONEY
•WHEN I ASK THE MACHINE FOR MONEY
•THEN THE MONEY SHOULD BE SUBTRACTED FROM
MY ACCOUNT
•AND THE MONEY SHOULD BE DELIVERED TO ME
•AND MY CARD SHOULD BE RETURNED
14. Did you remember where?
• In tester spreadsheets, sometimes with columns
instead of given/when/then
• It is almost the syntax for the gherkin language!!
15. What if I use the same business words to name things in
code?
16. Let’s try that!
• GIVEN THERE IS MONEY IN MY ACCOUNT
• AND I HAVE A VALID CARD
• AND THE MONEY DISPENSER HAS MONEY
• WHEN I ASK THE MACHINE FOR MONEY
• THEN THE MONEY SHOULD BE SUBTRACTED
FROM MY ACCOUNT
• AND THE MONEY SHOULD BE DELIVERED TO
ME
• AND MY CARD SHOULD BE RETURNED
•ACCOUNT.HAS_ENOUGH_MONEY?(VALUE)
•CARD.VALID?
•DISPENSER.HAS_MONEY?
•MACHINE.I_WANT(VALUE)
•ACCOUNT.SUBTRACT(VALUE)
•MACHINE.DELIVER_MONEY(VALUE)
•MACHINE.RETURN_CARD
19. BDD Development cycle
Talk to the client,
write a user story
or
Select a user
story
Detail the
story into
scenarions
Automate
scenarios with
selected tool
Run tests and
see them fail
Write ony
the code to
make tests
pass
Refactor
Almost the same as TDD?
20. OK, how is that different from TDD “Red,
green, refactor”?
• The main focus is not the test, in reality the automate step can be
skiped sometimes
• The main focus is on communication
• Test business behaviour not language dependent functions
• Behaviour is more important to the software than how it was
implemented
• The main focus in using a ubiquitous language like in DDD
• Using the ubiquitous language, the user story template and the
scenario template the communication with the entire team will
improve a lot
22. That same context sintaxe can be
automated by:
• Cucumber using gherkin - https://cucumber.io/
• Thoughtworks gauge - http://getgauge.io/
• Rspec can use that syntax to name the test specs
• Jbehave was created thinking about that
• Specflow using gherkin - http://www.specflow.org/
23. Sample gherkin code
Feature: A sample code for my presentation
As a speaker
I want to have some code samples
So that everyone understand what I'm talking about
Scenario: doing a simple google search
Given I'm on the google home page
When I fill the search field with "Urubatan"
Then I want to see "my web page" in the results
And I want to see "my facebook profile" in the results
24. Sample cucumber RuBY code
Given(/^I'm on the google home page$/) do
pending # express the regexp above with the code you wish you had
end
When(/^I fill the search field with "(.*?)"$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
Then(/^I want to see "(.*?)" in the results$/) do |arg1|
pending # express the regexp above with the code you wish you had
end
25. SAMPLE CUCUMBER JAVA CODE
public class MyStepdefs {
@cucumber.api.java.en.Then("^I want to see "([^"]*)" in the results$")
public void iWantToSeeInTheResults(String arg0) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
}
@cucumber.api.java.en.When("^I fill the search field with "([^"]*)"$")
public void iFillTheSearchFieldWith(String arg0) throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
}
@cucumber.api.java.en.Given("^I'm on the google home page$")
public void iMOnTheGoogleHomePage() throws Throwable {
// Write code here that turns the phrase above into concrete actions
throw new cucumber.api.PendingException();
}
}
26. Sample gauge code
A sample code for my presentation
=============
As a speaker, I want to have some code samples, So that everyone understand
what I'm talking about
doing a simple google search
-----------
* I'm on the google home page
* I fill the search field with "Urubatan"
* I want to see "my web page" in the results
* I want to see "my facebook profile" in the results
27. SAMPLE GAUGE JAVA CODE
public class SampleGauge {
@Step("I'm on the google home page")
public void goToGoogle() {
// Step implementation
}
@Step("I fill the search field with <value>")
public void fillField(String value) {
// Step implementation
}
@Step("I want to see <addr> in the results")
public void checkValue(String value) {
// Step implementation
}
}
28. Sample gauge ruby code
step "I'm on the google home page" do
end
step "I fill the search field with <name>" do |name|
end
step "I want to see <address> in the results" |address|
end
Tell the HP project story here, where BDD helped solve the fights between testers and developers
What if we try to work as a team, and everyone has access to everyone, and we talk with each other?
The developer can talk to the tester and to the client
The tester can talk to the client and the developer
Ubiquitous language needs to be a team effort, the client needs to define a dictionary and stick to it, the testers and developers should talk about everything using that dictionary, the code must be written using that same dictionary