TDD drogą do oświecenia w Scali

Post on 05-Dec-2014

280 views 1 download

description

Tomek i Konrad w przeciągu tych 45 minut pokażą "o co tak na prawdę w tym TDD chodzi?" a przy okazji, spojrzą na język Scala. Okazuje się bowiem, iż cykl znany jako Red-Green-Refactor znany z Test Driven Design nie tylko pomaga tworzyć dobry kod, ale również jest niezwykle pomocy podczas nauki języków - wystarczy spojrzeć na popularne serie ćwiczeń o nazwie Koans, dostępne dla wielu języków programowania. Sesja ta powinna być najcenniejsza dla osób które nie doświadczyły jeszcze ćwiczeń programistycznych w formie Kata bądź Code Retreat lub nie parujących się na co-dzień w pracy.

Transcript of TDD drogą do oświecenia w Scali

TDDdrogą do oświecenia w

Scali

Tomasz BorekKonrad Malawski

SFI 2013

@gmail.com

Tomasz Borek

LAFK => lafkblogs.wordpress.com

Java?Python?Scala?APL?

Testing?

TDD?REAL TDD?

ADHD?

Show of Hands

testach,

Scali,

poznawanie przez testy,

narzędziach.

Dziś będzie o:

Scala - język

ScalaTest - DSL

SBT - Simple Build Tool

Mózga nawet dwa!

Narzędzia:

Droga do TDD

Brak Manualne "PO" "PRZED" TDD

Błąd kompilacji ma znaczenie.

tak, zdarza się, a czasem nawet jest potrzebne!

PRAWDZIWY cykl TDD

minimum koduby przeszło

AcceptanceTDD

TDDevelopment vs TDDesign

Żywa, krzycząca dokumentacja

ATDD, dla UFO

it should "..." in pending

it should "do things" in { // ...}

ATDD, dla UFO

Tests!

ATDD, dla Anime

Tests!

nie "gada z bazą"nie potrzeba mu Internetu,

szybki,odpowiednio nazwany,

jasny, przejrzysty, klarowny,testuje jedną rzecz, nie dwie, nie tysiąc

Test jednostkowy

Struktura testubehaviour of "Something" it should "have expressive name" in { // given val anObject : UnderTest = new UnderTest();

// when val result = anObject.testedMethod();

// then result should be ("expressive");}

Struktura testubehaviour of "Something" it should "have expressive name" in { // given val anObject = new UnderTest

// when val result = anObject.testedMethod()

// then result should be ("expressive")}

The stairway to Scala...

... or highway to hell?

Scala is...

Simple,but

Hard.

Scala to język...

Funkcyjny,Obiektowy,

Statycznie typowany,idealny dla DSLi,

na JVMie,by Martin Odersky

Scala Collections

Scala Basics & Collections

def greet(p: Person) = println(s"Hello ${p.name}")

val people = List(tomek, konrad)

people foreach { person => greet(person)}

Scala Basics & Collections

val people: List[Person]def greet(p: Person)

people foreach { greet }

people foreach greet

Scala REPL

ReadEvaluate

PrintLoop

Eksplorowanie uzupełnia Testowanie

Scala Basics & Collections

Tests!

Cechy = Traits

object with wizard traits

object with nerd and wizard traits

object with ranger traits

Damage? Dice!

Cechy = Traits

class D6Dice extends RealDice(maxRoll = 6)

object D6 extends D6Dice

object P6 extends D6Dice with PredictableDice

Cechy = Traits

behavior of "Weapon"

it should "hit to cause damage"

behavior of "SimpleSword"

it should "cause D6 damage"

Cechy = Traits

Tests!

Cechy = Traits

behavior of "SimpleAxe"

it should "cause D6 damage"

// Axe, Sword... behave like Weapon

Cechy = Traits

Tests!

Cechy = Traits

behavior of "+10 DMG Axe"

it should "always cause > 10 damage"

Cechy = Traits

Tests!

Cechy = Traits

behavior of "Sword of Nyarlathotep"

it should "roll DMG using D20"it should "have base damage +10 DMG"it should "add 'panic' magic effect"

● DSLs,

● Collections,

● Pattern Matching,

● Traits

Podsumowanie - Scala

behaviour of "scala"

it should "ask them politely" in pending

it should "ask them loudly" in pending

it should "go eat" in pending

● SBT,

● REPL,

● ScalaTest,

● FlatSpec,

● Should Matchers,

● Live Templates

Podsumowanie - Narzędzia

● Droga do TDD● Testy przed != TDD● Cykl

● Błąd kompilacji == Pierwszy Red● Testy jednostkowe, nie integracyjne

● Testy jako Dokumentacja

● Given When Then

Podsumowanie - Testy

● SCKRK / Code Kata / Kraków Scala

● Tomasz Kaczanowski - practicalunittesting.com

● ScalaTest docs

● Scala docs

● Martin Odersky - Programming in Scala● Cay Horstmann - Scala for The Impatient● "Bruce Eckel's Atomic Scala" in pending ...

Podsumowanie - Linki

THANKS!

// todo implement thisbehaviour of "those who ask questions"

they should "ask them politely" in pending

they should "ask them loudly" in pending

they should "go eat" in pending

Konrad Malawski - twitter: @ktosoplTomasz Borek - @gmail.com

SFI 2013