Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Startup Spock #javajo

kyonmm
March 25, 2017

Startup Spock #javajo

Java女子部でSpockのハンズオンをしたときのスライドです。

kyonmm

March 25, 2017
Tweet

More Decks by kyonmm

Other Decks in Technology

Transcript

  1. SELF INTRODUCTION • ͖ΐΜ : @kyon_mm גࣜձࣾΦϯβϩʔυ • ςετΞʔΩςΫτɺδΣωϥϦετ •

    Groovy, F#, C#, Scala • جૅษڧձ, TDDBootCamp, ͳ͝΍͔Scrum 2
  2. Ҏ߱ͷηογϣϯͷͨΊʹ ؀ڥߏங • ιʔείʔυΛߋ৽ͨ͠ͷͰɺGitHub͔Β࠷৽ͷιʔείʔυΛམ ͱ͖͍ͯͯͩ͘͠͞ɻ(git reset --hard; git pull;) •

    IntelliJ IDEAͷ࣍ͷઃఆΛ͠·͠ΐ͏ɻ • Plugins -> Spock -> Install • Build Project Automatically • Edit Configurations -> Defaults -> JUnit -> Before LaunchͷBuildΛબ ୒ͯ͠࡟আ( - ϘλϯΛΫϦοΫ) 11
  3. ϝιουࢀরɺ ίϯετϥΫλࢀর͕ͳ͍ • ϝιουࢀর • Ϋϥε໊::ϝιου໊,ΦϒδΣΫτ໊::ϝιου໊
 (ಛʹ)ϥϜμͱͷซ༻Ͱ؆ܿͳهड़Λ࣮ݱͰ͖Δɻ
 Stream.of("javajo", "jjug", "kyon_mm").forEach(System.out::println)

    • GroovyͰ͸ϝιουࢀরɺίϯετϥΫλࢀরͷॻ͖ํΛαϙʔτ͍ͯ͠ͳ͍ɻ • GroovyͷΫϩʔδϟͰ͸Ҿ਺Λ໌ࣔ͠ͳ͍ͱ͖͸ݩͷΦϒδΣΫτ͕ it ͰΘͨͬ ͯ͘ΔͷͰɺ{ println(it) }ͷΑ͏ʹ࢖͏ɻ • src/test/groovy/example/startup/incompatible/java8/MethodReference.groovy 14
  4. ഑ྻϦςϥϧ͕ͳ͍ • ഑ྻϦςϥϧ • int[] xs = new int[]{1,2,3}; •

    GroovyͰ͸{}͸ΫϩʔδϟͳͷͰΤϥʔʹͳΔ • ϦετϦςϥϧͰArrayListΛੜ੒ͯ͠ɺޙΖʹas int[] Λ௥ه͢ Δɻ • src/test/groovy/example/startup/incompatible/java8/ ArrayLiteral.groovy 16
  5. Α͘ΈΔͰ͋Ζ͏ Τϥʔϝοηʔδ • groovy.lang.MissingMethodException: No signature of method: example.startup.groovy.Keyword.newMethod() •

    example.startup.groovy.Keyword.newMethod͍ͬͯ͏ϝ ιουͳ͔ͬͨΑ • groovy.lang.MissingPropertyException: No such property: y for class: example.startup.groovy.Keyword • KeyWordΫϥεʹy͍ͬͯ͏ϓϩύςΟͳ͔ͬͨΑ 17
  6. JUNITͱͷൺֱ 25 JUnit Spock Specification Ϋϥε spock.lang.SpecificationΛܧঝ Feature Method @Test

    SpockͷϥϕϧΛ࢖༻͢Δϝιου Helper Method ϝιουએݴ @Share Fixture Method @Before setupϝιου Fixture Method @After cleanupϝιου Fixture Method @BeforeClass setupSpecϝιου Fixture Method @AfterClass cleanupSpecϝιου
  7. SPOCKͷ࢖͍͔ͨ • Specification • given, when, then, and, where •

    power assert • setup, teardown, setupSpec, cleanupSpec • @Unroll, @Shared, @Ignore 26 src/test/groovy/example/startup/spock ഑ԼΛΈͳ͕Β
  8. TaskList ---------------------- add(Task) : TaskList delete(Task) : TaskList list(Task) :

    List<Task> search(String) : List<Task> search(Date, Date) : List<Task> searchFrom(Date) : List<Task> searchTo(Date) : List<Task> Task ---------------------- title : String dueTo : Date * 30
  9. TDD • ςετۦಈ։ൃ(Test Driven Development) • ςετ࣮૷ -> ϓϩμΫτ࣮૷ ->

    ϦϑΝΫλ Ϧϯά ͷ܁Γฦ͠Ͱ։ൃ͢Δɻ • ઃܭ͓Αͼ෼ੳͷख๏ 31
  10. TaskList ---------------------- add(Task) : TaskList delete(Task) : TaskList list(Task) :

    List<Task> search(String) : List<Task> search(Date, Date) : List<Task> searchFrom(Date) : List<Task> searchTo(Date) : List<Task> Task ---------------------- title : String dueTo : Date * 37