29
Solving communication problems in distributed teams with BDD Rodrigo Urubatan Developer, Writer, Crossfitter, Archer

Rubyconf2016 - Solving communication problems in distributed teams with BDD

Embed Size (px)

Citation preview

Page 1: Rubyconf2016 - Solving communication problems in distributed teams with BDD

Solving communication problems in distributed

teams with BDDRodrigo Urubatan

Developer, Writer, Crossfitter, Archer

Page 2: Rubyconf2016 - Solving communication problems in distributed teams with BDD

What is the biggest problem in software projects?

Page 3: Rubyconf2016 - Solving communication problems in distributed teams with BDD

What is the root cause for this problem?

Client DeveloperTester

Page 4: Rubyconf2016 - Solving communication problems in distributed teams with BDD

What do we need to solve this problem?

Page 5: Rubyconf2016 - Solving communication problems in distributed teams with BDD

How to solve this problem?

Page 6: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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

Page 7: Rubyconf2016 - Solving communication problems in distributed teams with BDD
Page 8: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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

Page 9: Rubyconf2016 - Solving communication problems in distributed teams with BDD

Need to see it everywhere

Page 10: Rubyconf2016 - Solving communication problems in distributed teams with BDD

But it is not enough!

Page 11: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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

Page 12: Rubyconf2016 - Solving communication problems in distributed teams with BDD

But how much details can I get?

Page 13: Rubyconf2016 - Solving communication problems in distributed teams with BDD

Have you seen that sintaxe anywhere before?

Page 14: Rubyconf2016 - Solving communication problems in distributed teams with BDD

Did you remember where?

• In tester spreadsheets, sometimes with columns instead of given/when/then

• It is almost the syntax for the gherkin language!!

Page 15: Rubyconf2016 - Solving communication problems in distributed teams with BDD

What if I use the same business words to name things in code?

Page 16: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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

Page 17: Rubyconf2016 - Solving communication problems in distributed teams with BDD

Wow! Everyone talks the same language!

Page 18: Rubyconf2016 - Solving communication problems in distributed teams with BDD
Page 19: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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?

Page 20: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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

Page 21: Rubyconf2016 - Solving communication problems in distributed teams with BDD

Haven’t we forgot about test automation?

Page 22: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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/

Page 23: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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

Page 24: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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

Page 25: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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(); }}

Page 26: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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

Page 27: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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 }}

Page 28: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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

Page 29: Rubyconf2016 - Solving communication problems in distributed teams with BDD

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