2. Что такое Cucumber?
Cucumber (Wikipedia) приложение для запуска
автоматических приемочных
тестов, написанных в стиле BDD.
3. Установка Cucumber
Сначала надо установить Ruby и
RubyGems, а затем выполнить
команду для установки Cucumber
gem install cucumber
4. Пример Feature
Feature:
In order to check a calculator
As a regular user
I want ...
Scenario: Checking that calc works
fine
// Steps
Scenario: Checking something else
// Steps
5. Пример Сценария
Scenario: Checking that
calc works fine
Given
When
And
And
And
Then
I
I
I
I
I
I
have a calculator
press 5
press +
press 6
press =
should see 11
6. Как работает Cucumber
Щ нхиш
ю
рр
1
2
When I press 5 Cucumber
Step
Definitions
When /^I press (d+)$/ do |digit|
@calculator.pressed digit
end
3
@calculator.pressed digit
@calculator.value.should == expected_value
7. Синтаксис
Шаблоны сценариев.
Scenario Outline: testing different
calculators
Given I have a calculator "<calculator
brand>"
When I press 5+5=
Then I should see <result>
Examples:
|calculator brand|result|
|Casio
|10
|
|Sony
|10
|
|Broken One
|5
|
8. Как готовить Cucumber
Шаг 1. Пишем сценарий.
Scenario: Check the calc button "5"
Given I have a calculator
When I press 5
Then I should see 5
9. Как готовить Cucumber
Шаг 2. Реализовываем step definitions
Given /^I have a calculator$/ do
@calc = Calculator.new
end
When /^I press (d+)$/ do |digit|
@calc.pressed digit
end
Then /^I should see (d+)$/do |value|
@calc.screenvalue.should == value
end
10. Как готовить Cucumber
Шаг 3. Пишем код.
class Calculator
def initialize
@screen = ""
end
def pressed digit
@screen += digit
end
def screenvalue
@screen
end
end
11. Как готовить Cucumber
Шаг 4. Запускаем и радуемся.
Scenario: Check the calc button "5"
Given I have a calculator
When I press 5
Then I should see 5
1 scenario (1 passed)
3 steps (3 passed)
0m0.033s