cucumber presentation kiev meet up

70

Upload: dimakovalenko

Post on 14-Jan-2015

494 views

Category:

Technology


0 download

DESCRIPTION

 

TRANSCRIPT

Page 1: Cucumber Presentation Kiev Meet Up
Page 2: Cucumber Presentation Kiev Meet Up

Dima Kovalenko

@dimacuswww.agilesoftwaretesting.comwww.dimakovalenko.comlinkedin.com/in/dimakovalenko

Page 3: Cucumber Presentation Kiev Meet Up

Past Experience

Page 4: Cucumber Presentation Kiev Meet Up

Disclaimer

> Dima.kind_of?(Developer)=> false

Page 5: Cucumber Presentation Kiev Meet Up

Why automated tests?

Page 6: Cucumber Presentation Kiev Meet Up

Why automated tests?

•Too expensive

•Too much work to create

•Not enough staff to maintain

•Never know the coverage level

•No one but developers knows what is being tested

Page 7: Cucumber Presentation Kiev Meet Up

We don’t need Automated Tests!

Page 8: Cucumber Presentation Kiev Meet Up

We don’t need Automated Tests!

The EndSee You all at Selenium 2012!

Page 9: Cucumber Presentation Kiev Meet Up
Page 10: Cucumber Presentation Kiev Meet Up

Selenium and Cucumber

Img Source: http://pickledillies.homestead.com/

Page 11: Cucumber Presentation Kiev Meet Up

Overview

•Set the stage

•Introduce Cucumber

•Good features

•Bad features

•???

•Profit!

Page 12: Cucumber Presentation Kiev Meet Up

Assumptions

•Startup or small business

•Understaffed

•Inadequate test coverage

•Need to defend existence of having automated tests to business.

Page 13: Cucumber Presentation Kiev Meet Up

The Stage

Page 14: Cucumber Presentation Kiev Meet Up

The Stage

•First casualty of an agile development environment is documentation. - me

Page 15: Cucumber Presentation Kiev Meet Up

The Stage

•First casualty of an agile development environment is documentation. - me

•No written test cases to speak of

Page 16: Cucumber Presentation Kiev Meet Up

The Stage

•First casualty of an agile development environment is documentation. - me

•No written test cases to speak of

•Need to deliver features, NOW!!!

Page 17: Cucumber Presentation Kiev Meet Up

The Stage

•First casualty of an agile development environment is documentation. - me

•No written test cases to speak of

•Need to deliver features, NOW!!!

•Groupon: Weekly deployments

Page 18: Cucumber Presentation Kiev Meet Up

The Stage•First casualty of an agile

development environment is documentation. - me

•No written test cases to speak of

•Need to deliver features, NOW!!!

•Groupon: Weekly deployments

•IMVU: Up to 50 deploys a day• http://timothyfitz.wordpress.com/2009/02/10/continuous-d

eployment-at-imvu-doing-the-impossible-fifty-times-a-day/

Page 19: Cucumber Presentation Kiev Meet Up

Why automated tests?

•Too expensive

•Too much work to create

•Not enough staff to maintain

•Never know the coverage level

•No one but developers knows what is being tested

Page 20: Cucumber Presentation Kiev Meet Up

Cucumber

Page 21: Cucumber Presentation Kiev Meet Up

Cucumber

•A BDD framework to help with TDD and other TLAs

Page 22: Cucumber Presentation Kiev Meet Up

Cucumber

•A BDD framework to help with TDD and other TLAs

•It’s Agile, Promotes Synergy, Enterprise, will shift Paradigms and completely Web 2.0

Page 23: Cucumber Presentation Kiev Meet Up

Cucumber

•A BDD framework to help with TDD and other TLAs

•It’s Agile, Promotes Synergy, Enterprise, will shift Paradigms and completely Web 2.0

•You too can be BUZZ WORD compliant!

Page 24: Cucumber Presentation Kiev Meet Up

Img Source: http://www.themoreyouknow.com/

Page 25: Cucumber Presentation Kiev Meet Up

Natural Language@searchFeature: Searching For Hello World, and some more overview of the feature that we are trying to test

@google Scenario: User Searches for Hello World on Google.com Given I'm on Google's Home Page And I search for Hello World

Then I should see Wikipedia's Hello World article as 1st result

@bing Scenario: User Searches for Hello World on Bing.com Given I'm on Bing's Home Page And I search for Hello World

Then I should see car videos as first result

Page 26: Cucumber Presentation Kiev Meet Up

Step DefinitionsGiven /^I'm on Google's Home Page$/ do @selenium.open "www.google.com"end

Given /^I'm on Bing's Home Page$/ do @selenium.open "www.bing.com"end

When /^I search for Hello World$/ do @selenium.type "q", "Hello World"end

Then /^I should see Wikipedia's Hello World article as 1st result$/ do assert_stuffend

Then /^I should see car videos as first result$/ do assert_stuffend

Page 27: Cucumber Presentation Kiev Meet Up

Why automated tests?

•Too expensive

•Too much work to create

•Not enough staff to maintain

•Never know the coverage level

•No one but developers knows what is being tested

Page 28: Cucumber Presentation Kiev Meet Up

Who should be writing tests?

Page 29: Cucumber Presentation Kiev Meet Up

Who should be writing tests?

•Developers

•Unit, Integration, Functional

Page 30: Cucumber Presentation Kiev Meet Up

Who should be writing tests?

•Developers

•Unit, Integration, Functional

•QAs

•Functional, End-To-End

Page 31: Cucumber Presentation Kiev Meet Up

Who should be writing tests?

•Developers

•Unit, Integration, Functional

•QAs

•Functional, End-To-End

•Everyone else

•At least the feature definitions

Page 32: Cucumber Presentation Kiev Meet Up

Why automated tests?

•Too expensive

•Too much work to create

•Not enough staff to maintain

•Never know the coverage level

•No one but developers knows what is being tested

Page 33: Cucumber Presentation Kiev Meet Up

Mind Map Solution

Page 34: Cucumber Presentation Kiev Meet Up

Why automated tests?

•Too expensive

•Too much work to create

•Not enough staff to maintain

•Never know the coverage level

•No one but developers knows what is being tested

Page 35: Cucumber Presentation Kiev Meet Up

Good Features•Tags

•Encourages BDD/TDD

•Supports multiple test drivers

•Selenium 1 and Selenium 2 support

•Multilingual

• i18n support

•Readable test results

Page 36: Cucumber Presentation Kiev Meet Up

Tags@searchFeature: Searching For Hello World, and some more overview of the feature that we are trying to test

@google @selenium Scenario: User Searches for Hello World on Google.com Given I'm on Google's Home Page And I search for Hello World

Then I should see Wikipedia's Hello World article as 1st result

@bing Scenario: User Searches for Hello World on Bing.com Given I'm on Bing's Home Page And I search for Hello World

Then I should see car videos as first result

Page 37: Cucumber Presentation Kiev Meet Up

Tags@searchFeature: Searching For Hello World, and some more overview of the feature that we are trying to test

@google @selenium Scenario: User Searches for Hello World on Google.com Given I'm on Google's Home Page And I search for Hello World

Then I should see Wikipedia's Hello World article as 1st result

@bing Scenario: User Searches for Hello World on Bing.com Given I'm on Bing's Home Page And I search for Hello World

Then I should see car videos as first result

Page 38: Cucumber Presentation Kiev Meet Up

Encourages BDD/TDD

•Write feature description first

•Run test see it fail

•Create one step definition at the time

•Write functionality for the step

•Run test see it pass

Page 39: Cucumber Presentation Kiev Meet Up

First run

Page 40: Cucumber Presentation Kiev Meet Up

First run

Page 41: Cucumber Presentation Kiev Meet Up

Write Step Definitions

Page 42: Cucumber Presentation Kiev Meet Up

Write More Step Definitions

Page 43: Cucumber Presentation Kiev Meet Up

Even More Step Definitions

Page 44: Cucumber Presentation Kiev Meet Up

Multiple Test Drivers

Steam

CelerityCulerity

FireWatirSafariWatir

ChromeWatir Img Source: Wikipedia

Page 45: Cucumber Presentation Kiev Meet Up

Selenium 1 supportBefore do |scenario| @selenium = Selenium::Client::Driver.new( :host => "localhost", :port => 4444, :browser => “firefox”, :url => “www.google.com”)end

Page 46: Cucumber Presentation Kiev Meet Up

Selenium 1 Tip

Use Hpricot Or Nokogiri!!!

page = Hpricot(@selenium.get_html_source)

Page 47: Cucumber Presentation Kiev Meet Up
Page 48: Cucumber Presentation Kiev Meet Up
Page 49: Cucumber Presentation Kiev Meet Up

Selenium 2 support

Page 50: Cucumber Presentation Kiev Meet Up

Selenium 2 support

•Capybara + Selenium = Love

Page 51: Cucumber Presentation Kiev Meet Up

Selenium 2 support

•Capybara + Selenium = Love

•Capybara + Selenium + Rails = .......

Page 52: Cucumber Presentation Kiev Meet Up

Capybara

•Uses Nokogiri

•Uses XPath outside of browser

•Works outside of rails

Page 53: Cucumber Presentation Kiev Meet Up

MultilingualJVM: JRuby, Java

.NET: IronRuby, IronRuby .NET, MonoAdoby Flex: FunFX, Melomel

PythonErlangGroovyScala

ClosureJavascript

Spring

Page 54: Cucumber Presentation Kiev Meet Up

Java Step Definitionpackage cukes;

import cuke4duke.annotation.I18n.EN.Given;import java.util.List;import java.util.ArrayList;

public class BellySteps { private List<String> belly = new ArrayList<String>();

@Given("I have (\\d+) cukes in my belly") public void bellyCukes(int cukes) { for(int i = 0; i < cukes; i++) { belly.add("cuke " + i); } }}

Page 55: Cucumber Presentation Kiev Meet Up

i18n

Page 56: Cucumber Presentation Kiev Meet Up

i18nФункционал: Сложение чисел Чтобы не складывать в уме Все, у кого с этим туго Хотят автоматическое сложение целых чисел

Сценарий: Сложение двух целых чисел Допустим я ввожу число 50 И затем ввожу число 70 Если я нажимаю "+" То результатом должно быть число 120

Page 57: Cucumber Presentation Kiev Meet Up

i18n Chinese

功能 : 加法 為了避免愚蠢的錯誤 作為一個數學白痴 我希望有人能告訴我兩個數相加的結果

場景大綱 : 將兩個數相加 假設我已經在計算機上輸入 < 數值 _1> 而且我已經在計算機上輸入 < 數值 _2> 當我按下 < 按鈕 > 那麼螢幕上應該顯示 < 結果 >

Page 58: Cucumber Presentation Kiev Meet Up

i18n LOLz

OH HAI: STUFFING

MISHUN: CUCUMBR I CAN HAZ IN TEH BEGINNIN 3 CUCUMBRZ WEN I EAT 2 CUCUMBRZ DEN I HAS 2 CUCUMBERZ IN MAH BELLY AN IN TEH END 1 CUCUMBRZ KTHXBAI

Page 59: Cucumber Presentation Kiev Meet Up

Readable Test Results

Page 60: Cucumber Presentation Kiev Meet Up

Bad Features

•Regex step definitions

•Hard To find Step Definitions

•Slower

•Natural language parser

•Messy directory structure

Page 61: Cucumber Presentation Kiev Meet Up

Regex Step Definitions

•Good: Reuse Definitions

•Bad:

• Then /^(?:|I )should see "([^\"]*)"(?: within "([^\"]*)")?$/ do

Page 62: Cucumber Presentation Kiev Meet Up

Hard to find Step Definitions

cucumber-tmbundle

Vim Rails

Page 63: Cucumber Presentation Kiev Meet Up

Bad Features

•Regex step definitions

•Hard To find Step Definitions

•Slower

•Natural language parser

•Messy directory structure

Page 64: Cucumber Presentation Kiev Meet Up

Conclusion

•Cucumber is a great tool to

•Describe Features

•Document Features

•Get the whole team involved

•However, it has downsides also

Page 65: Cucumber Presentation Kiev Meet Up

@dhhRSpec offends me aesthetically with no discernible benefit for its added complexity over test/unit.

Page 66: Cucumber Presentation Kiev Meet Up

@dhhRSpec offends me aesthetically with no discernible benefit for its added complexity over test/unit.

Cucumber makes no sense to me unless you have clients reading the tests. Why would you build a test-specific parser for English?

Page 67: Cucumber Presentation Kiev Meet Up

@dhhRSpec offends me aesthetically with no discernible benefit for its added complexity over test/unit.

Cucumber makes no sense to me unless you have clients reading the tests. Why would you build a test-specific parser for English?

The important thing is of course that we get people testing, so tools shouldn't matter too much....

Page 68: Cucumber Presentation Kiev Meet Up

Work @ Groupon

www.groupon.com/techjobs

Page 69: Cucumber Presentation Kiev Meet Up

The End

Page 70: Cucumber Presentation Kiev Meet Up