SlideShare uma empresa Scribd logo
1 de 92
Baixar para ler offline
Behavior-Driven Development
      с RSpec и Cucumber
      Стефан Кънев
      http://skanev.com/
      27.06.2009, TechCamp.eu




Tuesday, April 27, 2010
Автоматизирано тестване




Tuesday, April 27, 2010
Unit Tests


                    Test-Driven Development


        Behavior-Driven Development
Tuesday, April 27, 2010
1. Unit test-ове
                    2. Test-Driven
                    3. Behavior-Driven
                    4. RSpec
                    5. Cucumber
Tuesday, April 27, 2010
1. Unit test-ове
                    2. Test-Driven
                    3. Behavior-Driven
                    4. RSpec
                    5. Cucumber
Tuesday, April 27, 2010
class Programmer
      def implement_a_change(project, change)
        files = self.open_related_files(project, change)
        while true
          self.attempt_change(change, files)
          project.run()
          result = self.click_around_and_test(project)
          project.stop()
          break if result.successful?
        end
        self.commit_code(files)
        self.hope_everything_went_ok()
      end
    end


Tuesday, April 27, 2010
Repetitive...




Tuesday, April 27, 2010
...boring...




Tuesday, April 27, 2010
...error-prone




Tuesday, April 27, 2010
Машина, която да го
                           прави вместо нас
Tuesday, April 27, 2010
Програма, която да го
                            прави вместо нас
Tuesday, April 27, 2010
Unit Test




Tuesday, April 27, 2010
Пишем код, който
                 проверява дали друг код
                    работи правилно.


Tuesday, April 27, 2010
С един бутон




                          Да                  Не
Tuesday, April 27, 2010
caladan:trane aquarius$ rake spec
        (in /work/trane)
        ...............................................................
        ...............................................................
        ...............................................................
        ..................

        Finished in 8.334414 seconds

        207 examples, 0 failures




Tuesday, April 27, 2010
caladan:trane aquarius$ rake spec
       (in /work/trane)
       ................................................................
       ................................................................
       ................................................................
       .....F.........

       1)
       'User should know something' FAILED
       expected: "something",
            got: "nothing" (using ==)
       ./spec/models/user_spec.rb:32:

       Finished in 8.123368 seconds

       207 examples, 1 failure




Tuesday, April 27, 2010
I can has value?



Tuesday, April 27, 2010
Време

Tuesday, April 27, 2010
Regression testing




Tuesday, April 27, 2010
Tuesday, April 27, 2010
Tuesday, April 27, 2010
Tuesday, April 27, 2010
Tuesday, April 27, 2010
Документация
          (развален английски + стари версии = fun)

Tuesday, April 27, 2010
Спецификация




Tuesday, April 27, 2010
Tuesday, April 27, 2010
1. Unit test-ове
                    2. Test-Driven
                    3. Behavior-Driven
                    4. RSpec
                    5. Cucumber
Tuesday, April 27, 2010
Unit test-овете са
                   просто инструмент



Tuesday, April 27, 2010
Test-Driven Development е
          подход към писането на
          софтуер


Tuesday, April 27, 2010
test-first




Tuesday, April 27, 2010
red/green/refactor




Tuesday, April 27, 2010
red/green/refactor


          Възможно най-простия тест,
          който проверява функцио-
          налността и не минава.


Tuesday, April 27, 2010
red/green/refactor


          Най-простата имплементация,
          която кара тестът да минава
          успешно.


Tuesday, April 27, 2010
red/green/refactor


          Отстраняване на повторения,
          докато кодът не стане
          достатъчно качествен.


Tuesday, April 27, 2010
Tuesday, April 27, 2010
малки стъпки




Tuesday, April 27, 2010
Test-Driven Design




Tuesday, April 27, 2010
Преизползваемост




Tuesday, April 27, 2010
Low coupling




Tuesday, April 27, 2010
Добър интерфейс




Tuesday, April 27, 2010
scope creep




Tuesday, April 27, 2010
up-front design




Tuesday, April 27, 2010
1. Unit test-ове
                    2. Test-Driven
                    3. Behavior-Driven
                    4. RSpec
                    5. Cucumber
Tuesday, April 27, 2010
Test-Driven Development
                          is not about testing



Tuesday, April 27, 2010
TDD ≠ QA



Tuesday, April 27, 2010
Опитните TDD-ри
             използват процеса за
           да открият поведението,
           което системата трябва
                   да има.

Tuesday, April 27, 2010
Behavior-Driven
                           Development


Tuesday, April 27, 2010
BDD ≈ TDD++



Tuesday, April 27, 2010
"Getting the words right"




Tuesday, April 27, 2010
Test-Driven         Behavior-Driven




Tuesday, April 27, 2010
Assertion   Expectation




Tuesday, April 27, 2010
Test Method        Code Example




Tuesday, April 27, 2010
Test Case       Example Group




Tuesday, April 27, 2010
Domain-Driven Design




Tuesday, April 27, 2010
Domain Driven
          Design
          Eric Evans




Tuesday, April 27, 2010
Близки до проблемната
                        област думи



Tuesday, April 27, 2010
Разбираем за
                          бизнеса език



Tuesday, April 27, 2010
BDD = TDD + DDD
                               (TLA FTW)




Tuesday, April 27, 2010
Tuesday, April 27, 2010
BDD = TDD + DDD




Tuesday, April 27, 2010
BDD = TDD + DDD
                BDD = (T + D)DD




Tuesday, April 27, 2010
BDD = TDD + DDD
                BDD = (T + D)DD
                B=T+D



Tuesday, April 27, 2010
BDD = TDD + DDD
                BDD = (T + D)DD
                B=T+D
                интензитет = време + доза

Tuesday, April 27, 2010
1. Unit test-ове
                    2. Test-Driven
                    3. Behavior-Driven
                    4. RSpec
                    5. Cucumber
Tuesday, April 27, 2010
Друг "синтаксис"




Tuesday, April 27, 2010
Друг "синтаксис"


                xUnit     assert_equal 42, answer




Tuesday, April 27, 2010
Друг "синтаксис"


                xUnit     assert_equal 42, answer

                RSpec     answer.should equal(42)




Tuesday, April 27, 2010
Друг "синтаксис"


                xUnit     assert_equal 42, answer

                RSpec     answer.should equal(42)

                English   Answer should equal 42




Tuesday, April 27, 2010
Tuesday, April 27, 2010
assert_equal 42, result




Tuesday, April 27, 2010
assert_equal 42, result
                          result.should == 42




Tuesday, April 27, 2010
assert_equal 42, result
                          result.should == 42
    assert result.nil?




Tuesday, April 27, 2010
assert_equal 42, result
                          result.should == 42
    assert result.nil?
                          result.should be_nil




Tuesday, April 27, 2010
assert_equal 42, result
                          result.should == 42
    assert result.nil?
                          result.should be_nil
    assert result.kind_of?(User)




Tuesday, April 27, 2010
assert_equal 42, result
                          result.should == 42
    assert result.nil?
                          result.should be_nil
    assert result.kind_of?(User)
                          result.should be_kind_of(User)




Tuesday, April 27, 2010
assert_equal 42, result
                          result.should == 42
    assert result.nil?
                          result.should be_nil
    assert result.kind_of?(User)
                          result.should be_kind_of(User)
    assert [], blog.posts




Tuesday, April 27, 2010
assert_equal 42, result
                          result.should == 42
    assert result.nil?
                          result.should be_nil
    assert result.kind_of?(User)
                          result.should be_kind_of(User)
    assert [], blog.posts
                          blog.should have(:no).posts




Tuesday, April 27, 2010
assert_equal 42, result
                          result.should == 42
    assert result.nil?
                          result.should be_nil
    assert result.kind_of?(User)
                          result.should be_kind_of(User)
    assert [], blog.posts
                          blog.should have(:no).posts
    assert 5, blog.posts.size



Tuesday, April 27, 2010
assert_equal 42, result
                          result.should == 42
    assert result.nil?
                          result.should be_nil
    assert result.kind_of?(User)
                          result.should be_kind_of(User)
    assert [], blog.posts
                          blog.should have(:no).posts
    assert 5, blog.posts.size
                          blog.should have(5).posts

Tuesday, April 27, 2010
Tuesday, April 27, 2010
assert_raise(InvalidRecord) do
                     user.save!
                   end




Tuesday, April 27, 2010
assert_raise(InvalidRecord) do
                     user.save!
                   end

                   lambda { user.save! }.should raise_error(InvalidRecord)




Tuesday, April 27, 2010
assert_raise(InvalidRecord) do
                     user.save!
                   end

                   lambda { user.save! }.should raise_error(InvalidRecord)

                   assert_difference "User.count", 1 do
                     user.create!
                   end




Tuesday, April 27, 2010
assert_raise(InvalidRecord) do
                     user.save!
                   end

                   lambda { user.save! }.should raise_error(InvalidRecord)

                   assert_difference "User.count", 1 do
                     user.create!
                   end

                   lambda {
                     user.save!
                   }.should change { User.count }.by(1)




Tuesday, April 27, 2010
class Stack < Test::Unit::TestCase
                            def set_up()
                              @stack = Stack.new
                            end

                            def test_empty
                              assert @stack.empty?
                              @stack.push 42
                              assert !@stack.empty?
                            end

                            def test_pop
                              @stack.push 42
                              @stack.push 5
                              assert_equal 5, @stack.pop
                              assert_equal 42, @stack.pop
                              asser_raise(StackEmptyError) { @stack.pop }
                            end
                          end



Tuesday, April 27, 2010
describe Stack do
           before(:each) do
             @stack = Stack.new
           end

              it "should be able to tell whether it is empty" do
                @stack.should be_empty
                @stack.push 42
                @stack.should_not be_empty?
              end

           it "should pop the items in reverse order" do
             @stack.push 42
             @stack.push 5
             @stack.pop.should == 5
             @stack.pop.should == 42
             lambda { @stack.pop }.should raise_error(StackEmptyError)
           end
         end



Tuesday, April 27, 2010
describe Stack do
        context "(empty stack)" do
          it "should be empty"
          it "#pop should raise an exception"
        end

        context "(non-empty stack)" do
          it "should not be empty"
          it "#pop should return the top element"
          it "#pop should remove the top element"
        end
      end


Tuesday, April 27, 2010
Tuesday, April 27, 2010
1. Unit test-ове
                    2. Test-Driven
                    3. Behavior-Driven
                    4. RSpec
                    5. Cucumber
Tuesday, April 27, 2010
Feature: Manage posts
                    In order to be able to spread wisdom
                    the blogger
                    wants to be able to write about anything he wants

                          Scenario: Writing a new post
                            Given that there are no posts
                            And I am logged in
                            When I go to the new post page
                            And I fill "Title" with "F1rst p0st"
                            And I fill "Content" with "This is my first post"
                            And I press "Publish"
                            Then I should be on the front page
                            And I should see "This is my first post"
                            And there should be a new post called "F1rst p0st"




Tuesday, April 27, 2010
Given /^I am logged in$/ do
        end

        When /^I go to (.*?)$/ do |page|
        end

        When /^I fill "([^"]*)" with "([^"]*)"$/ do |field, content|
        end

        When /^I press "([^"]*)"$/ do |button_name|
        end

        Then /^I should be on (.*?)$/ do |page|
        end

        Then /^I should see "([^"]*)"$/ do |text1|
        end

        Then /^there should be a new post called "([^"]*)"$/ do |name|
        end


Tuesday, April 27, 2010
Tuesday, April 27, 2010

Mais conteúdo relacionado

Semelhante a Behavior-Driven Development с RSpec и Cucumber

2010.10.30 steven sustaining tdd agile tour shenzhen
2010.10.30 steven sustaining tdd   agile tour shenzhen2010.10.30 steven sustaining tdd   agile tour shenzhen
2010.10.30 steven sustaining tdd agile tour shenzhen
Odd-e
 
Orientação a Objetos na prática em php
Orientação a Objetos na prática em phpOrientação a Objetos na prática em php
Orientação a Objetos na prática em php
Campus Party Brasil
 

Semelhante a Behavior-Driven Development с RSpec и Cucumber (8)

Continous Delivery in Action
Continous Delivery in ActionContinous Delivery in Action
Continous Delivery in Action
 
RoRoRoomba - Ruby on Rails on Roomba Railsconf 2012
RoRoRoomba - Ruby on Rails on Roomba Railsconf 2012RoRoRoomba - Ruby on Rails on Roomba Railsconf 2012
RoRoRoomba - Ruby on Rails on Roomba Railsconf 2012
 
Campus Party 2010
Campus Party 2010Campus Party 2010
Campus Party 2010
 
Пак ли този Rails?
Пак ли този Rails?Пак ли този Rails?
Пак ли този Rails?
 
Test Driven Development - Caleb Tutty
Test Driven Development - Caleb TuttyTest Driven Development - Caleb Tutty
Test Driven Development - Caleb Tutty
 
2010.10.30 steven sustaining tdd agile tour shenzhen
2010.10.30 steven sustaining tdd   agile tour shenzhen2010.10.30 steven sustaining tdd   agile tour shenzhen
2010.10.30 steven sustaining tdd agile tour shenzhen
 
Orientação a Objetos na prática em php
Orientação a Objetos na prática em phpOrientação a Objetos na prática em php
Orientação a Objetos na prática em php
 
IT Talk TestNG 6 vs JUnit 4
IT Talk TestNG 6 vs JUnit 4IT Talk TestNG 6 vs JUnit 4
IT Talk TestNG 6 vs JUnit 4
 

Mais de Stefan Kanev

5. HTTP и приятели
5. HTTP и приятели5. HTTP и приятели
5. HTTP и приятели
Stefan Kanev
 
4. Метапрограмиране
4. Метапрограмиране4. Метапрограмиране
4. Метапрограмиране
Stefan Kanev
 
3. Обекти и класове
3. Обекти и класове3. Обекти и класове
3. Обекти и класове
Stefan Kanev
 
1. Въведение в Ruby
1. Въведение в Ruby1. Въведение в Ruby
1. Въведение в Ruby
Stefan Kanev
 

Mais de Stefan Kanev (17)

Ruby 0 2012
Ruby 0 2012Ruby 0 2012
Ruby 0 2012
 
Ruby 0
Ruby 0Ruby 0
Ruby 0
 
Debugging Habits
Debugging HabitsDebugging Habits
Debugging Habits
 
Защо MongoDB?
Защо MongoDB?Защо MongoDB?
Защо MongoDB?
 
Как блогът ми ме направи по-добър професионалист
Как блогът ми ме направи по-добър професионалистКак блогът ми ме направи по-добър професионалист
Как блогът ми ме направи по-добър професионалист
 
Щастливият програмист 2.0
Щастливият програмист 2.0Щастливият програмист 2.0
Щастливият програмист 2.0
 
The Happy Programmer
The Happy ProgrammerThe Happy Programmer
The Happy Programmer
 
ФМИ Python: Agile & Friends
ФМИ Python: Agile & FriendsФМИ Python: Agile & Friends
ФМИ Python: Agile & Friends
 
Test-Driven Development + Refactoring
Test-Driven Development + RefactoringTest-Driven Development + Refactoring
Test-Driven Development + Refactoring
 
за Ruby
за Rubyза Ruby
за Ruby
 
Защо Ruby on Rails
Защо Ruby on RailsЗащо Ruby on Rails
Защо Ruby on Rails
 
5. HTTP и приятели
5. HTTP и приятели5. HTTP и приятели
5. HTTP и приятели
 
4. Метапрограмиране
4. Метапрограмиране4. Метапрограмиране
4. Метапрограмиране
 
3. Обекти и класове
3. Обекти и класове3. Обекти и класове
3. Обекти и класове
 
2. Функционални Закачки
2. Функционални Закачки2. Функционални Закачки
2. Функционални Закачки
 
1. Въведение в Ruby
1. Въведение в Ruby1. Въведение в Ruby
1. Въведение в Ruby
 
0. За курса, Ruby и Rails
0. За курса, Ruby и Rails0. За курса, Ruby и Rails
0. За курса, Ruby и Rails
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 

Behavior-Driven Development с RSpec и Cucumber