Top Banner
BDD BRZMI PIĘKNIE. TYLKO DLACZEGO CZĘSTO SIE NIE UDAJE? @tommykaczmarek
39

4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

Jul 16, 2015

Download

Software

PROIDEA
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

BDD BRZMI PIĘKNIE.TYLKO DLACZEGO CZĘSTO SIE NIE UDAJE?

@tommykaczmarek

Page 2: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

@SCENARIO@Given

@When

@Then

Page 3: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

Scenario Aktywacja kartyGiven Użytkownik ma nieaktywną karteWhen Użytkownik aktywuje karte podając $pinThen Aktywacja ma status $status i zostanie wyświelony komunikat $komunikat

Examples:| pin | status | komunikat || 2244 | OK | Ustawienie kodu PIN przebiegło pomyślnie || 22a2 | FAIL | Dozwolone tylko liczby || 62628812 | FAIL | Długość kodu PIN powinna wynosić 4 znaki |

Page 4: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

public class CardActivationSteps

private BankCardApi bankCardApi; private BankCard bankCard;

public CardActivationSteps(BankCardApi bankCardApi) this.bankCardApi = bankCardApi;

@Given("Użytkownik ma nieaktywną karte") public void cardIsInactive() bankCard = bankCardApi.prepareNewCard();

@When("Użytkownik aktywuje karte podając $pin") public void cardIsUsedForAFirstTime(@Named("pin") String pin) bankCardApi.activate(bankCard, pin);

@Then("Aktywacja ma status $status i zostanie wyświelony komunikat $komunikat") public void pinGenerationRequest(@Named("status") String status, @Named("komunikat") String komunikat) ActivationResult activationResult = bankCardApi.activationStatus(bankCard); assertThat(activationResult.getStatus().name()).isEqualTo(status); assertThat(activationResult.getError()).isEqualTo(komunikat);

Page 5: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek
Page 6: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek
Page 7: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

Scenario Użytkownik zakłada konto w serwisieGiven Użytkownik zakłada kontoWhen Użytkownik poda imie $imie oraz nazwisko $nazwiskoThen Operacja ma status $status i zostanie wyświetlony komunikat $komunikatAnd Zostanie wyświetlony błąd : Nieprawidłowo wypełniony formularz

Examples:| imie | nazwisko | status | komunikat || Tomasz | Kaczmarek# | FAIL | Formularz zawiera błędy |

Page 8: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek
Page 9: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

KOMUNIKACJA

Page 10: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

DYSKUSJA

Page 11: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

PRZEJRZYSTOŚĆ

Page 12: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

SPISYWANIESCENARIUSZY

Page 13: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

A WIĘC CHCESZ UŻYĆ W PROJEKCIEBDD...

Page 14: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

“Mamy scruma ale nie robimy standupówbo nie mamy problemów z komunikacją”

Page 15: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek
Page 16: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

DLACZEGO CHCĘ UŻYWAĆ NOWEGONARZĘDZIACo chcę osiągnąć?

Jak będę mierzyć efektywność?

Page 17: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

“Przecież to prawie jak mamy u siebie”

“Analityk będzie pisać scenariusze wformule Given/When/Then”

Page 18: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek
Page 19: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

SPECYFIKACJE SĄSPISYWANE

Page 20: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

“To taki inny sposób na skrypty testowe”

Page 21: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

Scenario ­ Zmiana miasta w profilu użytkownikaGiven Użytkownik zaloguje się do serwisu jako zenon And Wprowadzi hasło zenon1And Kliknie na zakładke UstawieniaAnd Przejdzie do ZaawansowaneAnd Przejdzie do sekcji profilWhen Naciśnie przycisk edytuj profilThen Zostanie przekierowany do strony edycji profiluWhen Wprowadzi miasto zamieszkaniaAnd Naciśnie zapiszThen Profil zostanie zapisanyAnd Wyświetli sie informacja: Profil zapisany

Page 22: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek
Page 23: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

WARUNKI BRZEGOWE

Scenario Użytkownik zakłada konto w serwisieGiven Użytkownik zakłada kontoWhen Użytkownik poda imie $imie oraz nazwisko $nazwiskoThen Operacja ma status $status i zostanie wyświetlony komunikat $komunikatAnd Zostanie wyświetlony błąd : Nieprawidłowo wypełniony formularz

Examples:| imie | nazwisko | status | komunikat || Tomasz | Kaczmarek# | FAIL | Formularz zawiera błędy || Tomasz@ | Kaczmarek | FAIL | Formularz zawiera błędy || Tomasz | Kaczmarek11 | FAIL | Formularz zawiera błędy || Tomasz23 | Kaczmarek | FAIL | Formularz zawiera błędy || Tomasz | Kaczmarek_ | FAIL | Formularz zawiera błędy || Tomasz | Kaczmarek | FAIL | Formularz zawiera błędy || Tomasz | Kaczmarek% | FAIL | Formularz zawiera błędy || Tomasz | (Kaczmarek) | FAIL | Formularz zawiera błędy |

Page 24: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

NAZYWAJ SYTUACJEDOSŁOWNIE

Page 25: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

Given Gateway nie otrzyma ramki RFVS przez 30 sekundAnd Gateway nie może wysłać ramki H3DE do mediatoraWhen Użytkownik wykona akcje ROZPOZNAJThen Na ekranie wyświetli sie: System nie działa, sprobuj później.

Page 26: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

Given Mediator jest rozłączonyWhen Użytkownik wykona akcje ROZPOZNAJThen Na ekranie wyświetli sie: System nie działa, sprobuj później.

Page 27: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

“Ten scenariusz jest bardzo podobny dopoprzedniego. Utworzymy sobie wspólną

baze początkowych kroków dlascenariuszy.”

“Współdzielenie kodu!”

Page 28: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

DOBRE INTENCJE.NIEKONTROLOWANE KOPIOWANIE.

Page 29: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

OBSZERNE KROKI USTAWIAJĄCESYSTEM

Page 30: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

“Scenariusze będą uaktualniane wnastępnym sprincie po wdrożeniu na

produkcje.”

Page 31: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

CZY KTOŚ BĘDZIECZYTAĆ

SPECYFIKACJE?...PO NAPISANIU

Page 32: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

NIECZYTANE = NIECZYTELNEBARDZO SZYBKO..

Page 33: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

KTO BĘDZIE ODBIORCĄSPECYFIKACJI?

Page 34: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

DEVELOPERZY LEPIEJZROZUMIEJĄ TESTY

Page 35: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

“Na unit testy nie ma czasu bo mamyJBehave.”

Page 36: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

TESTY ZNASTAWIENIEM NA

ZACHOWANIE

Page 37: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

def "should activate inactive banking card"() given: "Użytkownik ma nieaktywną karte" bankCard = bankCardApi.prepareNewCard();

when: "Użytkownik aktywuje karte podając pin" bankCardApi.activate(bankCard, pin);

then: "Aktywacja ma status status i zostanie wyświelony komunikat komunikat" ActivationResult activationResult = bankCardApi.activationStatus(bankCard);

activationResult.getStatus().name() == status activationResult.getError() == message

where: pin | status | message "2244" | "OK" | "Ustawienie kodu PIN przebiegło pomyślnie" "22a2" | "FAIL" | "Dozwolone tylko liczby" "62628812" | "FAIL" | "Długość kodu PIN powinna wynosić 4 znaki"

Page 38: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

KOMUNIKACJASPISYWANIE SPECYFIKACJI

CZYTANIE SPECYFIKACJISPECYFIKACJA VS TESTY

Page 39: 4Developers 2015: Behavior Driven Development - sounds perfect but why are we failing? - Tomasz Kaczmarek

PYTANIA?