Globalcode	– Open4education
Testes – Solving communication
problems in distributed teams with
BDD
Rodrigo Urubatan
Developer, Writer, Crossfitter, Archer
Globalcode	– Open4education
What is the biggest
problem in software
projects?
Globalcode	– Open4education
What is the root cause
for this problem?
Globalcode	– Open4education
What do we need to
solve this problem?
Globalcode	– Open4education
How to solve this problem?
Globalcode	– Open4education
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
Globalcode	– Open4education
Globalcode	– Open4education
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
Globalcode	– Open4education
Need to see it everywhere
Globalcode	– Open4education
But it is not enough!
Globalcode	– Open4education
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
Globalcode	– Open4education
But how much details can I
get?
Globalcode	– Open4education
Have you seen that sintaxe anywhere before?
Globalcode	– Open4education
Did you remember where?
In tester spreadsheets, sometimes with
columns instead of given/when/then
It is almost the syntax for the gherkin
language!!
Globalcode	– Open4education
What if I use the same business words to name
things in code?
Globalcode	– Open4education
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?(VALU
E)
• CARD.VALID?
• DISPENSER.HAS_MONEY?
• MACHINE.I_WANT(VALUE)
• ACCOUNT.SUBTRACT(VALUE)
• MACHINE.DELIVER_MONEY(VALUE)
• MACHINE.RETURN_CARD
Globalcode	– Open4education
Wow! Everyone talks
the same language!
Globalcode	– Open4education
Globalcode	– Open4education
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 toolRun tests and
see them fail
Write ony
the code to
make tests
pass
Refactor
Almost the same as TDD?
Globalcode	– Open4education
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
Globalcode	– Open4education
Haven’t we forgot about test automation?
Globalcode	– Open4education
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/
Globalcode	– Open4education
Sample gherkin code
Feature:A sample code for my presentation
As a speaker
I wantto have some code samples
So thateveryone understand whatI'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 wantto see "my web page"in the results
And I wantto see "my facebook profile"in the results
Globalcode	– Open4education
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(/^Ifill the search field with "(.*?)"$/) do |arg1|
pending# express the regexp above with the code you wish you had
end
Then(/^Iwantto see "(.*?)" in the results$/) do |arg1|
pending# express the regexp above with the code you wish you had
end
Globalcode	– Open4education
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();
}
}
Globalcode	– Open4education
Sample gauge code
A sample code for my presentation
=============
As a speaker,Iwantto have some code samples,So thateveryone understandwhatI'm talking about
doing a simple googlesearch
-----------
* I'm on the google home page
* I fill the search field with "Urubatan"
* I wantto see "my web page"in the results
* I wantto see "my facebook profile"in the results
Globalcode	– Open4education
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
}
}
Globalcode	– Open4education
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
Globalcode	– Open4education
Rodrigo Urubatan
http://www.urubatan.com.br
http://sobrecodigo.com
Twitter @urubatan
http://github.com/urubatan
http://linkedin.com/in/urubatan
http://fb.com/urubatan

resolvendo problemas de comunicação em equipes distribuídas com bdd

  • 1.
    Globalcode – Open4education Testes –Solving communication problems in distributed teams with BDD Rodrigo Urubatan Developer, Writer, Crossfitter, Archer
  • 2.
    Globalcode – Open4education What isthe biggest problem in software projects?
  • 3.
    Globalcode – Open4education What isthe root cause for this problem?
  • 4.
    Globalcode – Open4education What dowe need to solve this problem?
  • 5.
  • 6.
    Globalcode – Open4education Ok, buthow’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.
    Globalcode – Open4education User Stories!! Asa … 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
  • 9.
  • 10.
  • 11.
    Globalcode – Open4education 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
  • 12.
  • 13.
    Globalcode – Open4education Have youseen that sintaxe anywhere before?
  • 14.
    Globalcode – Open4education Did youremember where? In tester spreadsheets, sometimes with columns instead of given/when/then It is almost the syntax for the gherkin language!!
  • 15.
    Globalcode – Open4education What ifI use the same business words to name things in code?
  • 16.
    Globalcode – Open4education Let’s trythat! • 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?(VALU E) • CARD.VALID? • DISPENSER.HAS_MONEY? • MACHINE.I_WANT(VALUE) • ACCOUNT.SUBTRACT(VALUE) • MACHINE.DELIVER_MONEY(VALUE) • MACHINE.RETURN_CARD
  • 17.
  • 18.
  • 19.
    Globalcode – Open4education BDD Developmentcycle Talk to the client, write a user story or Select a user story Detail the story into scenarions Automate scenarios with selected toolRun tests and see them fail Write ony the code to make tests pass Refactor Almost the same as TDD?
  • 20.
    Globalcode – Open4education OK, howis 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
  • 21.
    Globalcode – Open4education Haven’t weforgot about test automation?
  • 22.
    Globalcode – Open4education That samecontext 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.
    Globalcode – Open4education Sample gherkincode Feature:A sample code for my presentation As a speaker I wantto have some code samples So thateveryone understand whatI'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 wantto see "my web page"in the results And I wantto see "my facebook profile"in the results
  • 24.
    Globalcode – Open4education Sample cucumberRuBY code Given(/^I'm on the google home page$/) do pending# express the regexp above with the code you wish you had end When(/^Ifill the search field with "(.*?)"$/) do |arg1| pending# express the regexp above with the code you wish you had end Then(/^Iwantto see "(.*?)" in the results$/) do |arg1| pending# express the regexp above with the code you wish you had end
  • 25.
    Globalcode – Open4education SAMPLE CUCUMBER JAVACODE 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.
    Globalcode – Open4education Sample gaugecode A sample code for my presentation ============= As a speaker,Iwantto have some code samples,So thateveryone understandwhatI'm talking about doing a simple googlesearch ----------- * I'm on the google home page * I fill the search field with "Urubatan" * I wantto see "my web page"in the results * I wantto see "my facebook profile"in the results
  • 27.
    Globalcode – Open4education SAMPLE GAUGEJAVA 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.
    Globalcode – Open4education Sample gaugeruby 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
  • 29.
    Globalcode – Open4education Rodrigo Urubatan http://www.urubatan.com.br http://sobrecodigo.com Twitter@urubatan http://github.com/urubatan http://linkedin.com/in/urubatan http://fb.com/urubatan