SlideShare a Scribd company logo
1 of 39
Download to read offline
TDD
drogą do oświecenia w
      Scali

       Tomasz Borek
      Konrad Malawski
         SFI 2013
Tomasz Borek
@gmail.com




               LAFK => lafkblogs.wordpress.com
Show of Hands

             Java?
            Python?
             Scala?
             APL?

            Testing?

              TDD?
           REAL TDD?
             ADHD?
Dziś będzie o:


                 testach,

                  Scali,

        poznawanie przez testy,

             narzędziach.
Narzędzia:


              Scala - język

             ScalaTest - DSL

        SBT - Simple Build Tool

                  Mózg
              a nawet dwa!
Droga do TDD




Brak   Manualne   "PO"   "PRZED"   TDD
PRAWDZIWY cykl TDD

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




             minimum kodu
             by przeszło




                    Błąd kompilacji ma znaczenie.
Żywa, krzycząca dokumentacja



          AcceptanceTDD


     TDDevelopment vs TDDesign
ATDD, dla UFO

it should "..." in pending

it should "do things" in {
  // ...
}
ATDD, dla UFO




          Tests!
ATDD, dla Anime




          Tests!
Test jednostkowy


             nie "gada z bazą"
        nie potrzeba mu Internetu,
                  szybki,
         odpowiednio nazwany,
      jasny, przejrzysty, klarowny,
           testuje jedną rzecz,
           nie dwie, nie tysiąc
Struktura testu
behaviour 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 testu
behaviour 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

              Read
             Evaluate
               Print
              Loop

 Eksplorowanie uzupełnia Testowanie
Scala Basics & Collections




           Tests!
Cechy = Traits

  object with                      object with
  wizard traits                    ranger traits


                  object with
                   nerd and
                   wizard 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"
Podsumowanie - Scala

● DSLs,
● Collections,
● Pattern Matching,
● Traits
Podsumowanie - Narzędzia

● SBT,
● REPL,
● ScalaTest,
● FlatSpec,
● Should Matchers,
● Live Templates
Podsumowanie - Testy

● Droga do TDD
● Testy przed != TDD
● Cykl
● Błąd kompilacji == Pierwszy Red
● Testy jednostkowe, nie integracyjne
● Testy jako Dokumentacja
● Given When Then
Podsumowanie - Linki

● 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 ...
THANKS!
// todo implement this
behaviour 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: @ktosopl
            Tomasz Borek - @gmail.com
                    SFI 2013

More Related Content

Viewers also liked

Scalding - the not-so-basics @ ScalaDays 2014
Scalding - the not-so-basics @ ScalaDays 2014Scalding - the not-so-basics @ ScalaDays 2014
Scalding - the not-so-basics @ ScalaDays 2014Konrad Malawski
 
Ebay legacy-code-retreat
Ebay legacy-code-retreatEbay legacy-code-retreat
Ebay legacy-code-retreatKonrad Malawski
 
Need for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsNeed for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsKonrad Malawski
 
KrakDroid: Scala on Android
KrakDroid: Scala on AndroidKrakDroid: Scala on Android
KrakDroid: Scala on AndroidKonrad Malawski
 
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)Konrad Malawski
 
Scalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeScalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeKonrad Malawski
 
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRKKonrad Malawski
 
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka StreamsFresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka StreamsKonrad Malawski
 
Disrupt 2 Grow - Devoxx 2013
Disrupt 2 Grow - Devoxx 2013Disrupt 2 Grow - Devoxx 2013
Disrupt 2 Grow - Devoxx 2013Konrad Malawski
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaKonrad Malawski
 
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...Konrad Malawski
 
The Need for Async @ ScalaWorld
The Need for Async @ ScalaWorldThe Need for Async @ ScalaWorld
The Need for Async @ ScalaWorldKonrad Malawski
 
Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016Konrad Malawski
 
How Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemHow Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemKonrad Malawski
 
Scala Types of Types @ Lambda Days
Scala Types of Types @ Lambda DaysScala Types of Types @ Lambda Days
Scala Types of Types @ Lambda DaysKonrad Malawski
 
DDDing Tools = Akka Persistence
DDDing Tools = Akka PersistenceDDDing Tools = Akka Persistence
DDDing Tools = Akka PersistenceKonrad Malawski
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneKonrad Malawski
 
End to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to SocketEnd to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to SocketKonrad Malawski
 
Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!Konrad Malawski
 
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Konrad Malawski
 

Viewers also liked (20)

Scalding - the not-so-basics @ ScalaDays 2014
Scalding - the not-so-basics @ ScalaDays 2014Scalding - the not-so-basics @ ScalaDays 2014
Scalding - the not-so-basics @ ScalaDays 2014
 
Ebay legacy-code-retreat
Ebay legacy-code-retreatEbay legacy-code-retreat
Ebay legacy-code-retreat
 
Need for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applicationsNeed for Async: Hot pursuit for scalable applications
Need for Async: Hot pursuit for scalable applications
 
KrakDroid: Scala on Android
KrakDroid: Scala on AndroidKrakDroid: Scala on Android
KrakDroid: Scala on Android
 
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
[Tokyo Scala User Group] Akka Streams & Reactive Streams (0.7)
 
Scalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of codeScalding - Hadoop Word Count in LESS than 70 lines of code
Scalding - Hadoop Word Count in LESS than 70 lines of code
 
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
100th SCKRK Meeting - best software engineering papers of 5 years of SCKRK
 
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka StreamsFresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
Fresh from the Oven (04.2015): Experimental Akka Typed and Akka Streams
 
Disrupt 2 Grow - Devoxx 2013
Disrupt 2 Grow - Devoxx 2013Disrupt 2 Grow - Devoxx 2013
Disrupt 2 Grow - Devoxx 2013
 
The things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and AkkaThe things we don't see – stories of Software, Scala and Akka
The things we don't see – stories of Software, Scala and Akka
 
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
[Japanese] How Reactive Streams and Akka Streams change the JVM Ecosystem @ R...
 
The Need for Async @ ScalaWorld
The Need for Async @ ScalaWorldThe Need for Async @ ScalaWorld
The Need for Async @ ScalaWorld
 
Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016Akka Streams in Action @ ScalaDays Berlin 2016
Akka Streams in Action @ ScalaDays Berlin 2016
 
How Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM EcosystemHow Reactive Streams & Akka Streams change the JVM Ecosystem
How Reactive Streams & Akka Streams change the JVM Ecosystem
 
Scala Types of Types @ Lambda Days
Scala Types of Types @ Lambda DaysScala Types of Types @ Lambda Days
Scala Types of Types @ Lambda Days
 
DDDing Tools = Akka Persistence
DDDing Tools = Akka PersistenceDDDing Tools = Akka Persistence
DDDing Tools = Akka Persistence
 
The Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOneThe Cloud-natives are RESTless @ JavaOne
The Cloud-natives are RESTless @ JavaOne
 
End to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to SocketEnd to End Akka Streams / Reactive Streams - from Business to Socket
End to End Akka Streams / Reactive Streams - from Business to Socket
 
Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!Reactive Streams, j.u.concurrent & Beyond!
Reactive Streams, j.u.concurrent & Beyond!
 
Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014Reactive Streams / Akka Streams - GeeCON Prague 2014
Reactive Streams / Akka Streams - GeeCON Prague 2014
 

Similar to TDD drogą do oświecenia w Scali

4Developers 2015: Property-based testing w języku Scala - Paweł Grajewski
4Developers 2015: Property-based testing w języku Scala - Paweł Grajewski4Developers 2015: Property-based testing w języku Scala - Paweł Grajewski
4Developers 2015: Property-based testing w języku Scala - Paweł GrajewskiPROIDEA
 
Programowanie w języku Scala
Programowanie w języku ScalaProgramowanie w języku Scala
Programowanie w języku ScalaDevCastZone
 
Metaprogramowanie w JS
Metaprogramowanie w JSMetaprogramowanie w JS
Metaprogramowanie w JSDawid Rusnak
 
TorqueBox - moc Javy, piękno Rubiego
TorqueBox - moc Javy, piękno RubiegoTorqueBox - moc Javy, piękno Rubiego
TorqueBox - moc Javy, piękno Rubiegomarekgoldmann
 
Noc informatyka - co ja wiem o testowaniu
Noc informatyka - co ja wiem  o testowaniuNoc informatyka - co ja wiem  o testowaniu
Noc informatyka - co ja wiem o testowaniuTomek Borek
 
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScriptTworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScriptKrzysztof Kotowicz
 

Similar to TDD drogą do oświecenia w Scali (7)

4Developers 2015: Property-based testing w języku Scala - Paweł Grajewski
4Developers 2015: Property-based testing w języku Scala - Paweł Grajewski4Developers 2015: Property-based testing w języku Scala - Paweł Grajewski
4Developers 2015: Property-based testing w języku Scala - Paweł Grajewski
 
Scala
ScalaScala
Scala
 
Programowanie w języku Scala
Programowanie w języku ScalaProgramowanie w języku Scala
Programowanie w języku Scala
 
Metaprogramowanie w JS
Metaprogramowanie w JSMetaprogramowanie w JS
Metaprogramowanie w JS
 
TorqueBox - moc Javy, piękno Rubiego
TorqueBox - moc Javy, piękno RubiegoTorqueBox - moc Javy, piękno Rubiego
TorqueBox - moc Javy, piękno Rubiego
 
Noc informatyka - co ja wiem o testowaniu
Noc informatyka - co ja wiem  o testowaniuNoc informatyka - co ja wiem  o testowaniu
Noc informatyka - co ja wiem o testowaniu
 
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScriptTworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
Tworzenie, zaciemnianie i analiza złośliwego kodu JavaScript
 

More from Konrad Malawski

Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018Konrad Malawski
 
Akka Typed (quick talk) - JFokus 2018
Akka Typed (quick talk) - JFokus 2018Akka Typed (quick talk) - JFokus 2018
Akka Typed (quick talk) - JFokus 2018Konrad Malawski
 
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in'tScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in'tKonrad Malawski
 
State of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to comeState of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to comeKonrad Malawski
 
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYCBuilding a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYCKonrad Malawski
 
Akka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldAkka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldKonrad Malawski
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka StreamsKonrad Malawski
 
Not Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsNot Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsKonrad Malawski
 
Krakow communities @ 2016
Krakow communities @ 2016Krakow communities @ 2016
Krakow communities @ 2016Konrad Malawski
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsKonrad Malawski
 
2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japanese2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japaneseKonrad Malawski
 
Distributed Consensus A.K.A. "What do we eat for lunch?"
Distributed Consensus A.K.A. "What do we eat for lunch?"Distributed Consensus A.K.A. "What do we eat for lunch?"
Distributed Consensus A.K.A. "What do we eat for lunch?"Konrad Malawski
 

More from Konrad Malawski (13)

Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018Networks and Types - the Future of Akka @ ScalaDays NYC 2018
Networks and Types - the Future of Akka @ ScalaDays NYC 2018
 
Akka Typed (quick talk) - JFokus 2018
Akka Typed (quick talk) - JFokus 2018Akka Typed (quick talk) - JFokus 2018
Akka Typed (quick talk) - JFokus 2018
 
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in'tScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
ScalaSwarm 2017 Keynote: Tough this be madness yet theres method in't
 
State of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to comeState of Akka 2017 - The best is yet to come
State of Akka 2017 - The best is yet to come
 
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYCBuilding a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
Building a Reactive System with Akka - Workshop @ O'Reilly SAConf NYC
 
Akka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming WorldAkka-chan's Survival Guide for the Streaming World
Akka-chan's Survival Guide for the Streaming World
 
Reactive integrations with Akka Streams
Reactive integrations with Akka StreamsReactive integrations with Akka Streams
Reactive integrations with Akka Streams
 
Not Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabsNot Only Streams for Akademia JLabs
Not Only Streams for Akademia JLabs
 
Krakow communities @ 2016
Krakow communities @ 2016Krakow communities @ 2016
Krakow communities @ 2016
 
Zen of Akka
Zen of AkkaZen of Akka
Zen of Akka
 
Reactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka StreamsReactive Stream Processing with Akka Streams
Reactive Stream Processing with Akka Streams
 
2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japanese2014 akka-streams-tokyo-japanese
2014 akka-streams-tokyo-japanese
 
Distributed Consensus A.K.A. "What do we eat for lunch?"
Distributed Consensus A.K.A. "What do we eat for lunch?"Distributed Consensus A.K.A. "What do we eat for lunch?"
Distributed Consensus A.K.A. "What do we eat for lunch?"
 

TDD drogą do oświecenia w Scali

  • 1. TDD drogą do oświecenia w Scali Tomasz Borek Konrad Malawski SFI 2013
  • 2.
  • 3. Tomasz Borek @gmail.com LAFK => lafkblogs.wordpress.com
  • 4. Show of Hands Java? Python? Scala? APL? Testing? TDD? REAL TDD? ADHD?
  • 5. Dziś będzie o: testach, Scali, poznawanie przez testy, narzędziach.
  • 6. Narzędzia: Scala - język ScalaTest - DSL SBT - Simple Build Tool Mózg a nawet dwa!
  • 7. Droga do TDD Brak Manualne "PO" "PRZED" TDD
  • 8. PRAWDZIWY cykl TDD tak, zdarza się, a czasem nawet jest potrzebne! minimum kodu by przeszło Błąd kompilacji ma znaczenie.
  • 9. Żywa, krzycząca dokumentacja AcceptanceTDD TDDevelopment vs TDDesign
  • 10. ATDD, dla UFO it should "..." in pending it should "do things" in { // ... }
  • 11. ATDD, dla UFO Tests!
  • 12. ATDD, dla Anime Tests!
  • 13. Test jednostkowy nie "gada z bazą" nie potrzeba mu Internetu, szybki, odpowiednio nazwany, jasny, przejrzysty, klarowny, testuje jedną rzecz, nie dwie, nie tysiąc
  • 14. Struktura testu behaviour of "Something" it should "have expressive name" in { // given val anObject : UnderTest = new UnderTest(); // when val result = anObject.testedMethod(); // then result should be ("expressive"); }
  • 15. Struktura testu behaviour of "Something" it should "have expressive name" in { // given val anObject = new UnderTest // when val result = anObject.testedMethod() // then result should be ("expressive") }
  • 16. The stairway to Scala...
  • 17. ... or highway to hell?
  • 18. Scala is... Simple, but Hard.
  • 19. Scala to język... Funkcyjny, Obiektowy, Statycznie typowany, idealny dla DSLi, na JVMie, by Martin Odersky
  • 21. Scala Basics & Collections def greet(p: Person) = println(s"Hello ${p.name}") val people = List(tomek, konrad) people foreach { person => greet(person) }
  • 22. Scala Basics & Collections val people: List[Person] def greet(p: Person) people foreach { greet } people foreach greet
  • 23. Scala REPL Read Evaluate Print Loop Eksplorowanie uzupełnia Testowanie
  • 24. Scala Basics & Collections Tests!
  • 25. Cechy = Traits object with object with wizard traits ranger traits object with nerd and wizard traits
  • 27. Cechy = Traits class D6Dice extends RealDice(maxRoll = 6) object D6 extends D6Dice object P6 extends D6Dice with PredictableDice
  • 28. Cechy = Traits behavior of "Weapon" it should "hit to cause damage" behavior of "SimpleSword" it should "cause D6 damage"
  • 29. Cechy = Traits Tests!
  • 30. Cechy = Traits behavior of "SimpleAxe" it should "cause D6 damage" // Axe, Sword... behave like Weapon
  • 31. Cechy = Traits Tests!
  • 32. Cechy = Traits behavior of "+10 DMG Axe" it should "always cause > 10 damage"
  • 33. Cechy = Traits Tests!
  • 34. 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"
  • 35. Podsumowanie - Scala ● DSLs, ● Collections, ● Pattern Matching, ● Traits
  • 36. Podsumowanie - Narzędzia ● SBT, ● REPL, ● ScalaTest, ● FlatSpec, ● Should Matchers, ● Live Templates
  • 37. Podsumowanie - Testy ● Droga do TDD ● Testy przed != TDD ● Cykl ● Błąd kompilacji == Pierwszy Red ● Testy jednostkowe, nie integracyjne ● Testy jako Dokumentacja ● Given When Then
  • 38. Podsumowanie - Linki ● 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 ...
  • 39. THANKS! // todo implement this behaviour 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: @ktosopl Tomasz Borek - @gmail.com SFI 2013