Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Startup Spock #javajo
Search
kyonmm
PRO
March 25, 2017
Technology
0
2.5k
Startup Spock #javajo
Java女子部でSpockのハンズオンをしたときのスライドです。
kyonmm
PRO
March 25, 2017
Tweet
Share
More Decks by kyonmm
See All by kyonmm
SRE NEXT 2024 スライドみただけの感想 / Just a quick look at the slides for SRE NEXT 2024
kyonmm
PRO
2
420
Living Process #RSGT2024
kyonmm
PRO
3
2.3k
アジャイルクイズ王 2024 #RSGT2024 / agile quiz king 2024
kyonmm
PRO
0
120
プロダクトマネジメントのグローバルトレンド #pmconf2023 / Global Trends in Product Management
kyonmm
PRO
3
6.7k
スタートアップのためのアジャイルプラクティス -論文100本ノック- #xpjug / Agile Practice for Startup - Papers -
kyonmm
PRO
4
1.9k
アジャイルリーダークイズ王 2023 #scrummikawa / agile leader quiz king 2023
kyonmm
PRO
1
1.2k
アジャイルテストクイズ王2023 #scrumniigata / agile test quiz king
kyonmm
PRO
0
760
アジャイルコーチクイズ王 2023 #scrumfukuoka
kyonmm
PRO
0
2.1k
Living Management -Good bye Scrum, Hello Semilattice- #RSGT2023
kyonmm
PRO
1
8.1k
Other Decks in Technology
See All in Technology
AGIについてChatGPTに聞いてみた
blueb
0
130
初心者向けAWS Securityの勉強会mini Security-JAWSを9ヶ月ぐらい実施してきての近況
cmusudakeisuke
0
120
DMARC 対応の話 - MIXI CTO オフィスアワー #04
bbqallstars
1
160
【Pycon mini 東海 2024】Google Colaboratoryで試すVLM
kazuhitotakahashi
2
500
Why does continuous profiling matter to developers? #appdevelopercon
salaboy
0
190
Incident Response Practices: Waroom's Features and Future Challenges
rrreeeyyy
0
160
透過型SMTPプロキシによる送信メールの可観測性向上: Update Edition / Improved observability of outgoing emails with transparent smtp proxy: Update edition
linyows
2
210
【若手エンジニア応援LT会】ソフトウェアを学んできた私がインフラエンジニアを目指した理由
kazushi_ohata
0
150
IBC 2024 動画技術関連レポート / IBC 2024 Report
cyberagentdevelopers
PRO
0
110
第1回 国土交通省 データコンペ参加者向け勉強会③- Snowflake x estie編 -
estie
0
130
強いチームと開発生産性
onk
PRO
34
11k
Application Development WG Intro at AppDeveloperCon
salaboy
0
190
Featured
See All Featured
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
169
50k
How STYLIGHT went responsive
nonsquared
95
5.2k
Writing Fast Ruby
sferik
627
61k
Embracing the Ebb and Flow
colly
84
4.5k
Navigating Team Friction
lara
183
14k
What's in a price? How to price your products and services
michaelherold
243
12k
How to Think Like a Performance Engineer
csswizardry
20
1.1k
Happy Clients
brianwarren
98
6.7k
How to Ace a Technical Interview
jacobian
276
23k
Optimising Largest Contentful Paint
csswizardry
33
2.9k
Measuring & Analyzing Core Web Vitals
bluesmoon
4
120
Large-scale JavaScript Application Architecture
addyosmani
510
110k
Transcript
STARTUP SPOCK #JAVAJO kyon_mm 2017/03/25 1
SELF INTRODUCTION • ͖ΐΜ : @kyon_mm גࣜձࣾΦϯβϩʔυ • ςετΞʔΩςΫτɺδΣωϥϦετ •
Groovy, F#, C#, Scala • جૅษڧձ, TDDBootCamp, ͳ͔͝Scrum 2
THIS SESSION : TARGET • Javaݴޠͷجຊจ๏ͳΜͱͳ͘Θ͔͍ͬͯ ͯɺίʔυΛ͔͍ͨΓͰ͖Δɻ • Can you
code FizzBuzz ? 3
THIS SESSION : GOAL • SpockͰ؆୯ͳίʔυΛॻ͚ΔΑ͏ʹͳΔɻ 4
NO • Groovy LanguageΛ͍͜ͳ͢ • SexyͳCodeΛٻ͢Δ 5
MENU • https://github.com/kyonmm/startup-spock • Groovy Language for Java Language User
• Getting Start Spock • Spock with TDD 6
GROOVY LANGUAGE • Groovyͱ • Java8ඇޓͳͷ • ͓֮͑ͯ͘ͱศརͳͷ 7
GROOVYͱ • ਐతܕ͖(੩తܕݕࠪΦϓγϣϯ) • JVMͰಈ࡞͢Δɻgroovy-all.jarͱҰॹʹ͏ɻ • GradleɺJenkinsfileGroovyͷDSLɻ 8
GROOVYͱ • Java6ͱ΄΅ޓੑΛ͍ͨͬͯΔ͕ɺ Java7,Java8ͷ৽ػೳͱҰ෦ޓੑ͕ͳ͍ɻ (Java6Ҏલ͔ΒಠࣗͰ࣮͍ͯͨ͠Γͱ͔) • IntelliJ IDEA + Gradle
+ Spock͕ఆ൪ • OO͕ϕʔεɻޠኮRubyɺPythonͬΆ͞ɻ 9
GROOVY LANGUAGE • Groovyͱ • Java8ඇޓͳͷ • ͓֮͑ͯ͘ͱศརͳͷ 10
Ҏ߱ͷηογϣϯͷͨΊʹ ڥߏங • ιʔείʔυΛߋ৽ͨ͠ͷͰɺGitHub͔Β࠷৽ͷιʔείʔυΛམ ͱ͖͍ͯͯͩ͘͠͞ɻ(git reset --hard; git pull;) •
IntelliJ IDEAͷ࣍ͷઃఆΛ͠·͠ΐ͏ɻ • Plugins -> Spock -> Install • Build Project Automatically • Edit Configurations -> Defaults -> JUnit -> Before LaunchͷBuildΛબ ͯ͠আ( - ϘλϯΛΫϦοΫ) 11
JAVA8ͱඇޓͳͷ • ϥϜμͷΘΓʹΫϩʔδϟΛ͏ • ϝιουࢀরɺίϯετϥΫλࢀর͕ͳ͍ • try-with-resource͕͑ͳ͍ • ྻϦςϥϧ͕͑ͳ͍ 12
ϥϜμͷΘΓʹΫϩʔδϟ Λ͏ • ϥϜμ • ࣜɻJava7·ͰؔΦϒδΣΫτͰ࣮ݱ͍ͯͨ͠Γɻ • GroovyͰϥϜμͷॻ͖ํΛαϙʔτ͍ͯ͠ͳ͍ɻ • GroovyͰΫϩʔδϟͰ࣮ݱ͢Δɻ
• src/test/groovy/example/startup/incompatible/java8/ Lambda.groovy 13
ϝιουࢀরɺ ίϯετϥΫλࢀর͕ͳ͍ • ϝιουࢀর • Ϋϥε໊::ϝιου໊,ΦϒδΣΫτ໊::ϝιου໊ (ಛʹ)ϥϜμͱͷซ༻Ͱ؆ܿͳهड़Λ࣮ݱͰ͖Δɻ 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
TRY-WITH-RESOURCE • try-with-resource • ྫ֎Λߟྀͨ͠Ϧιʔε(IO)ͷΫϩʔζΛࣗಈతʹͬͯ͘ΕΔ • GroovyͰtry-with-resourceͷॻ͖ํΛαϙʔτ͍ͯ͠ͳ͍ɻ • ͨͩ͠ɺସखஈͱͯ͠ withCloseable
ϝιουΛ͏͜ͱ͕Ͱ͖ Δɻ • src/test/groovy/example/startup/incompatible/java8/ TryWithResource.groovy 15
ྻϦςϥϧ͕ͳ͍ • ྻϦςϥϧ • int[] xs = new int[]{1,2,3}; •
GroovyͰ{}ΫϩʔδϟͳͷͰΤϥʔʹͳΔ • ϦετϦςϥϧͰArrayListΛੜͯ͠ɺޙΖʹas int[] Λه͢ Δɻ • src/test/groovy/example/startup/incompatible/java8/ ArrayLiteral.groovy 16
Α͘ΈΔͰ͋Ζ͏ Τϥʔϝοηʔδ • 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
GROOVY LANGUAGE • Groovyͱ • Java8ඇޓͳͷ • ͓֮͑ͯ͘ͱศརͳͷ 18
͓֮͑ͯ͘ͱศརͳͷ • ϦετϦςϥϧ • ϚοϓϦςϥϧ • จࣈྻϦςϥϧ • ਖ਼نදݱϦςϥϧ •
GroovyͷίϨΫγϣϯૢ࡞ϝιουͱJavaͷstreamͱͷൺֱ 19
GROOVYͰΑ͔ͭ͘͏ॻ͖ํ • defͰએݴ • ςετϝιου໊จࣈྻએݴ 20
ͦͷଞҙ • booleanΛظ͞ΕΔॴ(ex. if(x))ʹɺBoolean Ҏ֎ͷࢀরܕ͕͍ͬͨ߹ͳ͍߹ ࣍ͷنଇͰఆ͞Ε·͢ɻ • "", [], [:],
0, null -> false • ͦΕΒҎ֎ -> true 21
MENU • Groovy Language for Java Language User • Getting
Start Spock • Spock with TDD 22
• Spockͱ • JUnitͱͷൺֱ • Spockͷ͍͔ͨ 23
SPOCKͱ • JUnit4ϕʔεͷGroovyͷςεςΟϯάϑϨʔ ϜϫʔΫ • BDDΛҙ͍ࣝͯ͠Δ • powerassert Spock͕ΦϦδϯ(ͩͱࢥ͏) 24
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ϝιου
SPOCKͷ͍͔ͨ • Specification • given, when, then, and, where •
power assert • setup, teardown, setupSpec, cleanupSpec • @Unroll, @Shared, @Ignore 26 src/test/groovy/example/startup/spock ԼΛΈͳ͕Β
MENU • Groovy Language for Java Language User • Getting
Start Spock • Spock with TDD 27
SPOCK WITH TDD • SpockͰTDDΛϖΞϓϩάϥϛϯάͰͬͯΈ· ͠ΐ͏ɻ • ͓ʮλεΫϦετ(λεΫཧπʔϧ)ʯͷ։ൃ Ͱ͢ɻ •
ࠓճγεςϜͷೖྗ෦লུ͠·͢ɻ(CUI, GUI ͷ։ൃলུ͠·͢ɻ) 28
λεΫϦετ • λεΫ໊ͱظΛొͨ͠ΓɺొࡁΈͷ ͷΛࢀরͨ͠Γɺআͨ͠ΓͰ͖Δɻ • λεΫ໊ظͰݕࡧͰ͖Δɻ 29
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
TDD • ςετۦಈ։ൃ(Test Driven Development) • ςετ࣮ -> ϓϩμΫτ࣮ ->
ϦϑΝΫλ Ϧϯά ͷ܁Γฦ͠Ͱ։ൃ͢Δɻ • ઃܭ͓Αͼੳͷख๏ 31
TDD3ݪଇ • ϓϩμΫτίʔυࣦഊ͢ΔςετίʔυΛ ޭͤ͞ΔͨΊ͚ͩʹॻ͘ • ςετίʔυࣦഊͤ͞ΔͨΊ͚ͩʹॻ͘ • ෳͷςετΛޭͤ͞ΔΑ͏ͳϓϩμΫτ ίʔυΛॻ͍͍͚ͯͳ͍ 32
ࠓΔTDDϥΠΫͳ։ൃ ςετ࣮ฤ 1. (͠ɺ͍·͔Β࣮͠Α͏ͱ͍ͯ͠Δͷطʹ୭͔͕࣮͠ ͯ͘Ε͍ͯͨΒ) ͲΜͳखॱͰɺͦΕΛ͏ͷ͔? 2. 1Ͱࢥ͍͍͍ͭͨํΛຊޠͰɺٙࣅίʔυͰ͍͍ͷͰς Ωετʹ͢Δɻ 3.
ͦΕΛSpockͷgiven, when, thenʹ͋ͯΊΔɻ 4. ਖ਼͍͠Groovyίʔυʹ͢Δɻ 33
ࠓΔTDDϥΠΫͳ։ൃ ϓϩμΫτ࣮ฤ 1. ςετΛ࣮ͨ͠Βςετ͕ಈ࡞͢ΔΑ͏ͳϓϩ μΫτΛ࣮͢Δɻ 2. ͠ɺ15ͨͬͯςετ͕ޭ͠ͳ͔ͬͨΒɺ͍ ·࣮ݱ͠Α͏ͱ͍ͯ͠ΔςετίʔυΛ@Ignore͠ ͯɺ͏͢͜͠খ͍͞ৼ͍Λ࣮ݱ͢Δςετίʔ υΛهड़ͯ͠ɺ࠶ϓϩμΫτ࣮ʹઓ͢Δɻ
34
ࠓΔTDDϥΠΫͳ։ൃ ϦϑΝΫλϦϯάฤ 1. ϓϩμΫτίʔυͷॏෳ͕͋Εڞ௨Խ 2. ςετίʔυͷॏෳ͕͋Εڞ௨Խ 3. ໊લʹҧײ͕͋ΕϦωʔϜϝιου ͷҠಈɺநग़ 35
λεΫϦετ • λεΫ໊ͱظΛొͨ͠ΓɺొࡁΈͷ ͷΛࢀরͨ͠Γɺআͨ͠ΓͰ͖Δɻ • λεΫ໊ظͰݕࡧͰ͖Δɻ 36
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
λεΫϦετ:Ճ͓ • λεΫ໊ͱظΛొͨ͠ΓɺొࡁΈͷͷΛ ࢀরͨ͠Γɺআͨ͠ΓͰ͖Δɻ • λεΫ໊ظͰݕࡧͰ͖Δɻ • λεΫΛӬଓԽ͓ͯ͘͜͠ͱͰɺΞϓϦ͕ऴྃ͠ ͯλεΫΛ͓͚ͯ͠Δ(JSONͱ͔CSVʹग़ྗ͠ ͯಡΈͩͤΔΑ͏ʹ͢Δ)
38