Startup Spock #javajo

405fe9ab689473f267e2cfbd95f78c75?s=47 kyonmm
March 25, 2017

Startup Spock #javajo

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

405fe9ab689473f267e2cfbd95f78c75?s=128

kyonmm

March 25, 2017
Tweet

Transcript

  1. 2.

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

    Groovy, F#, C#, Scala • جૅษڧձ, TDDBootCamp, ͳ͝΍͔Scrum 2
  2. 11.

    Ҏ߱ͷηογϣϯͷͨΊʹ ؀ڥߏங • ιʔείʔυΛߋ৽ͨ͠ͷͰɺGitHub͔Β࠷৽ͷιʔείʔυΛམ ͱ͖͍ͯͯͩ͘͠͞ɻ(git reset --hard; git pull;) •

    IntelliJ IDEAͷ࣍ͷઃఆΛ͠·͠ΐ͏ɻ • Plugins -> Spock -> Install • Build Project Automatically • Edit Configurations -> Defaults -> JUnit -> Before LaunchͷBuildΛબ ୒ͯ͠࡟আ( - ϘλϯΛΫϦοΫ) 11
  3. 14.

    ϝιουࢀরɺ ίϯετϥΫλࢀর͕ͳ͍ • ϝιουࢀর • Ϋϥε໊::ϝιου໊,ΦϒδΣΫτ໊::ϝιου໊
 (ಛʹ)ϥϜμͱͷซ༻Ͱ؆ܿͳهड़Λ࣮ݱͰ͖Δɻ
 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. 16.

    ഑ྻϦςϥϧ͕ͳ͍ • ഑ྻϦςϥϧ • int[] xs = new int[]{1,2,3}; •

    GroovyͰ͸{}͸ΫϩʔδϟͳͷͰΤϥʔʹͳΔ • ϦετϦςϥϧͰArrayListΛੜ੒ͯ͠ɺޙΖʹas int[] Λ௥ه͢ Δɻ • src/test/groovy/example/startup/incompatible/java8/ ArrayLiteral.groovy 16
  5. 17.

    Α͘ΈΔͰ͋Ζ͏ Τϥʔϝοηʔδ • 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. 22.
  7. 25.

    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ϝιου
  8. 26.

    SPOCKͷ࢖͍͔ͨ • Specification • given, when, then, and, where •

    power assert • setup, teardown, setupSpec, cleanupSpec • @Unroll, @Shared, @Ignore 26 src/test/groovy/example/startup/spock ഑ԼΛΈͳ͕Β
  9. 27.
  10. 30.

    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
  11. 31.

    TDD • ςετۦಈ։ൃ(Test Driven Development) • ςετ࣮૷ -> ϓϩμΫτ࣮૷ ->

    ϦϑΝΫλ Ϧϯά ͷ܁Γฦ͠Ͱ։ൃ͢Δɻ • ઃܭ͓Αͼ෼ੳͷख๏ 31
  12. 37.

    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