Upload
rodrigo-urubatan
View
115
Download
0
Embed Size (px)
Citation preview
Solving communication problems in distributed
teams with BDDRodrigo Urubatan
Developer, Writer, Crossfitter, Archer
What is the biggest problem in software projects?
What is the root cause for this problem?
Client DeveloperTester
What do we need to solve this problem?
How to solve this problem?
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
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
Need to see it everywhere
But it is not enough!
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
But how much details can I get?
Have you seen that sintaxe anywhere before?
Did you remember where?
• In tester spreadsheets, sometimes with columns instead of given/when/then
• It is almost the syntax for the gherkin language!!
What if I use the same business words to name things in code?
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
Wow! Everyone talks the same language!
BDD Development cycleTalk to the client, write a user story
orSelect 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?
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
Haven’t we forgot about test automation?
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/
Sample gherkin codeFeature: A sample code for my presentation
As 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
Sample cucumber RuBY code
Given(/^I'm on the google home page$/) do pending # express the regexp above with the code you wish you hadend
When(/^I fill the search field with "(.*?)"$/) do |arg1| pending # express the regexp above with the code you wish you hadend
Then(/^I want to see "(.*?)" in the results$/) do |arg1| pending # express the regexp above with the code you wish you hadend
SAMPLE CUCUMBER JAVA CODEpublic 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(); }}
Sample gauge codeA 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
SAMPLE GAUGE JAVA CODEpublic 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 }}
Sample gauge ruby codestep "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
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