The testing, The monkey & the BDD*

* Behavior-driven development

Created by Fabien Garcia

How to be sure that your web app is working?

You can trust developpers

You test it!

  1. You open a browser
  2. Visit the url of your application
  3. Fill in a form
  4. Check if the page should have the right content

And you do it for every single change, and you check for every single page, for every case

Advantages

  • You will become really good using your application

Drawbacks

  • Time consuming
  • Do not add value to the product
  • Do not let you focus on the user experience
  • Stupid task

A better solution?

Why not hire a monkey?

Advantages

  • You pay him with banana
  • It will do any stupid task
  • It's cute
  • It could repeat action as long as you give bananas

Drawbacks

  • It's a monkey ;-)
  • Training time
  • It could be loud
  • The office is not suitable

So let's find a better solution...

Let's hire a robot!

Advantages

  • You do not pay him
  • It will do any stupid task
  • It can test every part of your application, not just the interface
  • It could repeat action as long as you want
  • it's a computer

Drawbacks

  • Not cute like a monkey
  • Need to program this robot

How we programm this robot?

BDD*

* Behavior-driven development

Let see the frameworks to program our robot

Cucumber

It's a hight level framework testing

See more here

Let's see

Feature: Search
  In order to learn more
  As an information seeker
  I want to find more information

  Scenario: Find what I'm looking for
    Given I am on the search page
    And I have posts titled article top, other staff
    When I search for "article top"
    Then I should see
      """
      article top
      """

Under the hood!

You also need to define specific words

Given 'I am on the search page' do
  @browser.goto '/search'
end

When /I search for "(.*)"/ do |query|
  @browser.text_field(:name, 'q').set(query)
  @browser.button(:name, 'btnG').click
end

Then /I should see/ do |text\
  @browser.text.should =~ /#{text}/m
end

Advantages

  • The syntax is really similar to a real User-story
  • Framework force to write straightforward user stories
  • High level testing

Drawbacks

  • Need to learn the syntax
  • Syntax has no link with ruby
  • You need extra work to define specific task

Rspec with sugar*

* Capybara, Selenium-webdriver, Factory_girl_rails, ...

Framework for testing developer friendly and easy to read.

Let's see

describe "Search /blog" do
  it "should be able to search into the blog database" do
    post = FactoryGirl.create(:post)
    post2 = FactoryGirl.create(:post, title: 'other staff' )
    visit home_path
    fill_in 'search', :with => 'article top'
    click_on 'Search'
    page.should have_content("article top")
  end
end

Advantages

  • Really flexible allow hight level testing and unit test
  • With the sugar test case are easy to read for non developer
  • Close to the ruby
  • When it's written nothing to add
  • Could be integrate with Selenium

Drawbacks

  • Need to understand Ruby

How we know when test are passing?

You can trust your developpers

You use a building tool

It will give you a nice interface to build your project and see test result

(without knowing anything about development)

Jenkins

See more

One of the most famous, using Java to run on a server

  • Really powerful :-)
  • Any language
  • Really complexe to setup :-(

Travis

See more

Really powerfull solution for open source project

  • Really powerfull
  • Any language
  • Really easy to setup for opensource project
  • Really expensif/complex to setup for private project

Integrity

See more

Build tool made with ruby on rails

  • Really simple to use
  • Simple to setup and install
  • Works for any project
  • Any language
  • Too simple

Conclusion

Choose one but you have to test ! *

* except maybe for a small project 1 or 2 days long and with a really short life span and witch will never change !

To go further

Smart quotation

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true

Robert Wilensky

Question?

THE END

BY Fabien Garcia