SlideShare a Scribd company logo
TDD
drogą do oświecenia w
      Scali

       Tomasz Borek
      Konrad Malawski
         SFI 2013
TDD drogą do oświecenia w Scali
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

PDF
TDD drogą do oświecenia w Scali
PDF
Android at-xsolve
PDF
Scala dsls-dissecting-and-implementing-rogue
PDF
Git tak po prostu (SFI version)
PDF
Open soucerers - jak zacząć swoją przygodę z open source
PDF
JavaOne 2013: Java 8 - The Good Parts
PDF
Android my Scala @ JFokus 2013
PDF
HBase RowKey design for Akka Persistence
TDD drogą do oświecenia w Scali
Android at-xsolve
Scala dsls-dissecting-and-implementing-rogue
Git tak po prostu (SFI version)
Open soucerers - jak zacząć swoją przygodę z open source
JavaOne 2013: Java 8 - The Good Parts
Android my Scala @ JFokus 2013
HBase RowKey design for Akka Persistence

Viewers also liked (20)

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

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

PDF
4Developers 2015: Property-based testing w języku Scala - Paweł Grajewski
PDF
Konrad Gadzina: Test-Driven Gamedev - testy automatyczne a tworzenie gier
PDF
01 - Wprowadzenie do TDD
PDF
Czy na pewno wiesz już wszystko o testach jednostkowych w Javie?
PDF
Testy jednostkowe - 8 rzeczy, które musisz wiedzieć
PDF
4Developers 2015: Couple of words about testing in Java, Spock and BDD - Piot...
PDF
Scala
PPS
Poznańska grupa .Net spotkanie VI - Test Driven Development
PDF
4Developers 2018: Unit testing - introduction (Marek Kawczyński)
PDF
JUnit. Pragmatyczne testy jednostkowe w Javie
PDF
Najważniejszym czynnikiem dobrych testów, nie jest pisanie dobrych testów
PDF
Perl. Testowanie. Zapiski programisty
PPTX
Katarzyna Bylec, Testowanie - perspektywa programisty
4Developers 2015: Property-based testing w języku Scala - Paweł Grajewski
Konrad Gadzina: Test-Driven Gamedev - testy automatyczne a tworzenie gier
01 - Wprowadzenie do TDD
Czy na pewno wiesz już wszystko o testach jednostkowych w Javie?
Testy jednostkowe - 8 rzeczy, które musisz wiedzieć
4Developers 2015: Couple of words about testing in Java, Spock and BDD - Piot...
Scala
Poznańska grupa .Net spotkanie VI - Test Driven Development
4Developers 2018: Unit testing - introduction (Marek Kawczyński)
JUnit. Pragmatyczne testy jednostkowe w Javie
Najważniejszym czynnikiem dobrych testów, nie jest pisanie dobrych testów
Perl. Testowanie. Zapiski programisty
Katarzyna Bylec, Testowanie - perspektywa programisty
Ad

More from Konrad Malawski (13)

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