Globalcode – Open4education
Testes – Solving communication problems in distributed teams with
BDDRodrigo 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 keyWhat is the next important thing the system does not do yet?Use the business language to specify the softwareUse the business language to test the softwareUse the business language to write the softwareUse 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
ContextActionsVerification
• 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/thenIt 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?(VALUE)
• 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
orSelect 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 sometimesThe main focus is on communicationTest business behaviour not language dependent functionsBehaviour is more important to the software than how it was implementedThe main focus in using a ubiquitous language like in DDDUsing 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 specsJbehave was created thinking about thatSpecflow using gherkin -http://www.specflow.org/
Globalcode – Open4education
Sample gherkin code
Feature: A sample code for my presentationAs a speakerI want to have some code samplesSo that everyone understand what I'm talking about
Scenario: doing a simple google searchGiven I'm on the google home pageWhen I fill the search field with "Urubatan"Then I want to see "my web page" in the resultsAnd I want to see "my facebook profile" in the results
Globalcode – Open4education
Sample cucumber RuBY code
Given(/^I'm on the google home page$/) dopending # 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
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 actionsthrow 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 actionsthrow 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 actionsthrow new cucumber.api.PendingException();
}}
Globalcode – Open4education
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
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
endstep "I fill the search field with <name>" do |name|
endstep "I want to see <address> in the results" |address|
end
Globalcode – Open4education
Rodrigo Urubatanhttp://www.urubatan.com.brhttp://sobrecodigo.comTwitter @urubatanhttp://github.com/urubatanhttp://linkedin.com/in/urubatanhttp://fb.com/urubatan
Recommended