Lettuce
Behaviour Driven Development
Fatih Erikli
python developer @hipo

http://blog.fatiherikli.com
http://github.com/fatiherikli
Lettuce
• Python için bir Behaviour

Driven Development aracıdır.

• Lettuce, Ruby camiasındaki

Cucumber’dan esinlenmiştir.

• Senaryolar için Gherkin adında
bir DSL kullanır.
Amacı
• Test logic’ini ve senaryoları
birbirinden ayırır.

• Testlerin implementation’dan ziyade
user story güdümlü olması.

• Kodlama bilgisi olmayanların testleri
geliştirebilmesine olanak tanıması.
örnek
Feature: Commenting on documents
In order to discussing with the other users,
As an authenticated user,
I want to comment on a pattern

Scenario: users can comment on documents
Given I am logged in as user "tester"
And I create a pattern that named "Comment Model"
When go to the that pattern
And I type the "body" as "Test Comment"
When I submit the comment
Then the comment count of that pattern should be 1
Konseptler
Feature
Uygulamanın test edilecek
özellikleridir.
Örnek: Kullanıcının bir fotoğrafa
yorum girebilmesi.
Scenario
Bir özelliği çeşitli senaryolar ile test
edersiniz.
Örnek: Kullanıcı sisteme bağlı
değilken yorum girip girememesi.
Step
Senaryoları oluşturan adımlardır.
Örnek: Kullanıcının fotoğraf sayfasına
gelmesi.
Kurulum
pip install lettuce
/home/foo/projects/foobar-app
- app.py (flask, django, ya da başka bir şey)
+ tests
+ features
- steps.py (adım tanımlamalarınız)
- login.feature (senaryolar)
- photos.feature (senaryolar)
senaryolarımızı oluşturalım
feature
Feature: Login mechanism
In order to see my dashboard
As an anonymous user,
I want to login

Scenario: Login from homepage
Given I am an anonymous user
And I go to homepage
When I type “fatih” as username
And I type “123” as password
When I submit the form
Should I see “My dashboard” text on homepage
steps.py
from lettuce import step, world
@step(‘When I "(.*)" as username’)
def set_username(step, username):
world.username = username
@step(‘When I "(.*)" as password’)
def set_password(step, password):
world.password = password

@step(‘I submit the form’)
def submit(step):
world.login_is_done = (
world.username == “fatih” and
world.password == “123”
)
@step(‘I see “My dashboard” text on homepage’)
def homepage(step):
assert world.login_is_done
çalıştıralım
bir senaryo daha ekleyelim
feature
Feature: Login mechanism
In order to see my dashboard
As an anonymous user,
I want to login
...
Scenario: Login with wrong user credentials
Given I am an anonymous user
And I go to homepage
When I type the “fatih” as username
And I type the “321” as password
When I submit the form
Should I see “Wrong username or password” message
from lettuce import step, world
# ...
@step(‘I see “Wrong username or password” message’)
def homepage(step):
assert not world.login_is_done
Lettuce ile Behaviour Driven Development
Scenario outlines
Adımları belirlediğiniz tabular şeklindeki
verilerle yeniden kullanmanızı sağlar.
feature
Feature: Login mechanism
In order to see my dashboard
As an anonymous user,
I want to login
...
Scenario: Login with wrong user credentials
Given an user with <username> and <password>
When the user is loggin
Should see “Welcome” message
Examples:
| username | password |
| fatih

| 123

|

| admin
| foooo

| 321
| 123

|
|
başka bir örnek
Feature: Login mechanism
In order to see my dashboard
As an anonymous user,
I want to login
Background:
Given I am an anonymous user
And I go to homepage
Scenario: Login with wrong user credentials
When I type the “fatih” as username
And I type the “321” as password
When I submit the form
...
çalıştıralım
Background
scenarios
Birbirine benzeyen senaryolar için taslak
senaryolar hazırlayabilirsiniz.
Feature: Login mechanism
In order to see my dashboard
As an anonymous user,
I want to login
...
Background:
Given I have the numbers <number_one> and <number_two>
Then the result should be <result>
Examples:
| number_one | number_two | result

|

| 1
| 13

| 2
| 27

| 3
| 40

|
|

| 11

| 31

| 42

|
Senaryo örnekleri
•

https://github.com/fatiherikli/dbpatterns/tree/
master/tests

•

https://github.com/diaspora/diaspora/tree/
master/features

•

https://github.com/teambox/teambox/tree/dev/
features
teşekkürler

More Related Content

PDF
PHP Sunusu - 3
PDF
PDF
Klassify: Text Classification with Redis
PDF
Argüman Analizi Platformu
PDF
Arguman
PDF
Django Introduction
PDF
Graph Databases & NEO4J
PDF
Agent-based Models
PHP Sunusu - 3
Klassify: Text Classification with Redis
Argüman Analizi Platformu
Arguman
Django Introduction
Graph Databases & NEO4J
Agent-based Models
Ad

Lettuce ile Behaviour Driven Development