SlideShare ist ein Scribd-Unternehmen logo
1 von 72
Downloaden Sie, um offline zu lesen
Salenda
Testing Grails 3:
the good (unit), the bad (integration) and the ugly
(functional)
Greach ’17
Alberto De Ávila Hernández
A B O U T M E
✴ Software Engineer
✴ Team Lead at Salenda
✴ Groovy y Grails dev
✴ Testing obsessed
@alberto_deavila
S A L E N D A
S O F T WA R E D E V E L O P M E N T
Turnkey
development
Gold
Atlassian
Solution
Partner
Consulting and
support in
software
architecture and
analysis
Application
integration
Evolutionary support
of our own
developments or
inherited ones
@alberto_deavila
O B J E C T I V E S
@alberto_deavila
Objectives
F I R S T S T E P S
@alberto_deavila
First Steps
F I R S T S T E P S
@alberto_deavila
✴ Install Java 8
✴ Install sdkman
>$ curl -s "https://get.sdkman.io" | bash
>$ source "$HOME/.sdkman/bin/sdkman-init.sh"
✴ Install Grails 3.2.6
>$ sdk install grails 3.2.6
✴Clone: github.com/albertodeavila/testingGrails3
G U I D E
@alberto_deavila
✴ Testing types
✴ Testing in Grails 3
✴ Review app
✴ Unit testing
✴ Functional testing
✴ Integration testing
T E S T I N G T Y P E S
@alberto_deavila
Testing types
T E S T I N G T Y P E S
@alberto_deavila
Unit (the good)
T E S T I N G T Y P E S : U N I T
@alberto_deavila
✴ Test a small piece of code
✴ Simulate the rest of pieces
✴ Mock it
✴ Override behavior
✴ Independents on the environment
✴ Very quickly
T E S T I N G T Y P E S
@alberto_deavila
Integration (the bad)
T E S T I N G T Y P E S : I N T E G R AT I O N
@alberto_deavila
✴ Test a complete functionality
✴ Start the app
✴ Test inside the app
✴ Slow
✴ Depends on the environment
T E S T I N G T Y P E S
@alberto_deavila
Functional (the ugly)
T E S T I N G T Y P E S : F U N C T I O N A L
@alberto_deavila
✴ Test a complete functionality as a user
✴ Start the app
✴ Test outside the app
✴ Browsing the app / calling API
✴ Slow
✴ Not cross browser and some browser errors
T E S T I N G I N G R A I L S 3
@alberto_deavila
Testing in Grails 3
T E S T I N G I N G R A I L S 3
@alberto_deavila
✴ Plugins:
✴ Build test-data plugin
✴ Greenmail
✴ Rest client builder
✴ Spock
✴ Geb
T E S T I N G I N G R A I L S 3 : S P O C K
@alberto_deavila
Spock
T E S T I N G I N G R A I L S 3 : S P O C K
@alberto_deavila
✴ Describe test
✴ Blocks
✴ Mocks
✴ Data tables
✴ Fixture methods
✴ Tricks and recomendations
T E S T I N G I N G R A I L S 3 : S P O C K
@alberto_deavila
Describe test
T E S T I N G I N G R A I L S 3 : S P O C K
@alberto_deavila
✴ Given / Setup: preconditions and data
✴ Cleanup: postconditions
✴ When: action that trigger some outcome
✴ Then / Expect: assert outcome
✴ Where: applies varied data
Blocks
T E S T I N G I N G R A I L S 3 : S P O C K
@alberto_deavila
✴ Given, Expect
✴ Given, When, Then
✴ Given, When, Then, Where, Cleanup
✴ Given, Expect, Where
✴ When, Then, Where, Cleanup
Blocks: samples
T E S T I N G I N G R A I L S 3 : S P O C K
@alberto_deavila
Mocks Data tables
T E S T I N G I N G R A I L S 3 : S P O C K
@alberto_deavila
Fixture methods
T E S T I N G I N G R A I L S 3 : S P O C K
@alberto_deavila
✴ Use assert if there are { } in then clause
✴ You can catch exceptions with thrown
✴ @Build includes @Mock
✴ Use .buildWithoutSave() to avoid persist
✴ Use @ConfineMetaClassChanges ;)
Tricks & recommendations
R E V I E W A P P
@alberto_deavila
Review app
L E T ’ S G O T E S T
@alberto_deavila
Let’s go test!
U N I T T E S T I N G
@alberto_deavila
Unit testing
U N I T T E S T I N G
@alberto_deavila
✴ Unit test extends Specification
✴ @TestFor annotation to indicate what test
✴ @Mock annotation to simulate another entity
✴ @Build annotation to create default entities
U N I T T E S T I N G
@alberto_deavila
Domain classes
U N I T T E S T I N G : D O M A I N C L A S S E S
@alberto_deavila
✴ @TestFor with the domain class to test
✴ Check constraints and logic in domain class
✴ Implicit variable domain
✴ Tricks:
✴ Use the @Unroll to use different data
✴ Persistence can’t be tested with unit test
U N I T T E S T I N G : D O M A I N C L A S S E S
@alberto_deavila
Example:
EpisodeUnitSpec
U N I T T E S T I N G : D O M A I N C L A S S E S
@alberto_deavila
Exercise:
SerieUnitSpec
U N I T T E S T I N G
@alberto_deavila
Services
U N I T T E S T I N G : S E R V I C E S
@alberto_deavila
✴ Again @TestFor annotation
✴ Implicit variable service
✴ defineBeans: to inject services / beans
✴ Override method:
✴ Metaclass
✴ Mock
U N I T T E S T I N G : S E R V I C E S
@alberto_deavila
Example:
ActorServiceUnitSpec
U N I T T E S T I N G : S E R V I C E S
@alberto_deavila
Exercise:
SerieServiceUnitSpec
U N I T T E S T I N G
@alberto_deavila
Controllers
U N I T T E S T I N G : C O N T R O L L E R S
@alberto_deavila
✴ Implicit variable controller
✴ Helpers: view / model / response
✴ defineBeans: to inject services / beans
✴ If action return a map, model & view are null
✴ Save the action call return in a variable
✴ Bug: view doesn’t contains the template
U N I T T E S T I N G : C O N T R O L L E R S
@alberto_deavila
Example:
UserControllerUnitSpec
U N I T T E S T I N G : C O N T R O L L E R S
@alberto_deavila
Exercise:
ActorControllerUnitSpec
U N I T T E S T I N G : C O N T R O L L E R S
@alberto_deavila
Exercise:
SerieControllerUnitSpec
F U N C T I O N A L T E S T I N G
@alberto_deavila
Functional testing
F U N C T I O N A L T E S T I N G
@alberto_deavila
API
F U N C T I O N A L T E S T I N G
@alberto_deavila
✴ To test APIs you can use RestBuilder
✴ Use authentication
✴ Parse JSON / XML responses
F U N C T I O N A L T E S T I N G
@alberto_deavila
Example:
UserAPIFunctionalSpec
T E S T I N G I N G R A I L S 3 : G E B
@alberto_deavila
T E S T I N G I N G R A I L S 3 : G E B
@alberto_deavila
✴ Define:
✴ Pages: elements with jQuery style
selectors
✴ Modules: reuse content
✴ Create test to navigate through app
✴ Check content visible in browser
T E S T I N G I N G R A I L S 3 : G E B
@alberto_deavila
Pages
T E S T I N G I N G R A I L S 3 : G E B
@alberto_deavila
Test
F U N C T I O N A L T E S T I N G
@alberto_deavila
✴ Functional test extends GebSpec
✴ You can use beans with @Autowired
✴ To create data: Entity.withNewSession
✴ @Stepwise to execute test depending on
the previous
F U N C T I O N A L T E S T I N G
@alberto_deavila
✴ To execute JS code: js.exec(“alert(‘hi’)“)
✴ Go to some URL with: go(URL)
✴ Go to some Page defined: to SomePage
✴ Check if we are at a Page: at SomePage
✴ Use waitFor to ensure content is loaded
✴ To define Optional content: (required: false)
U N I T T E S T I N G : C O N T R O L L E R S
@alberto_deavila
Example:
UserFunctionalSpec
U N I T T E S T I N G : C O N T R O L L E R S
@alberto_deavila
Exercise:
SerieFunctionalSpec
I N T E G R AT I O N T E S T I N G
@alberto_deavila
Integration testing
I N T E G R AT I O N T E S T I N G
@alberto_deavila
✴ Functional test extends Specification
✴ Mark @Integration to differentiate from unit
✴ Like functional: use services with
@Autowired
✴ You don’t need to use @Build annotation
I N T E G R AT I O N T E S T I N G
@alberto_deavila
Domain classes
I N T E G R AT I O N T E S T I N G : D O M A I N C L A S S E S
@alberto_deavila
✴ Very similar to unit test
✴ You don’t need to mock domain classes :)
✴ You can check database persistence and
integrity
✴ Remember to Delete your created data or
use @Rollback
I N T E G R AT I O N T E S T I N G : D O M A I N C L A S S E S
@alberto_deavila
Example:
UserIntegrationSpec
I N T E G R AT I O N T E S T I N G : D O M A I N C L A S S E S
@alberto_deavila
Exercise:
EpisodeIntegrationSpec
I N T E G R AT I O N T E S T I N G
@alberto_deavila
Services
I N T E G R AT I O N T E S T I N G : S E R V I C E S
@alberto_deavila
✴ Define services with @Autowired
✴ Use it ;)
I N T E G R AT I O N T E S T I N G : S E R V I C E S
@alberto_deavila
Example:
SerieServiceIntegrationSpec
I N T E G R AT I O N T E S T I N G : S E R V I C E S
@alberto_deavila
Exercise:
UserServiceIntegrationSpec
I N T E G R AT I O N T E S T I N G
@alberto_deavila
Controllers
I N T E G R AT I O N T E S T I N G : C O N T R O L L E R S
@alberto_deavila
Grails docs:
“To integration test controllers it is recommended
you use create-functional-test command to create a
Geb functional test.”
I N T E G R AT I O N T E S T I N G : C O N T R O L L E R S
@alberto_deavila
✴ @Autowire Controller instance
✴ Define a bean WebApplicationContext
✴ To allow make request GrailsWebMockUtil.
bindMockWebRequest (context)
I N T E G R AT I O N T E S T I N G : C O N T R O L L E R S
@alberto_deavila
✴If action make redirect, ensure you have
controller specified
✴ Use modelAndView to obtain
✴ View name
✴ Renderer data
I N T E G R AT I O N T E S T I N G : C O N T R O L L E R S
@alberto_deavila
Example:
SerieControllerIntegrationSpec
I N T E G R AT I O N T E S T I N G : C O N T R O L L E R S
@alberto_deavila
Exercise:
UserControllerIntegrationSpec
Q U E S T I O N S
@alberto_deavila
That’s all!Thank you!!
Q U E S T I O N S
@alberto_deavila
Questions

Weitere ähnliche Inhalte

Andere mochten auch

Functional testing the_good_the_bad_and_the_ugly
Functional testing the_good_the_bad_and_the_uglyFunctional testing the_good_the_bad_and_the_ugly
Functional testing the_good_the_bad_and_the_uglyJohn Ferguson Smart Limited
 
Do you get alerts before your contracts expire
Do you get alerts before your contracts expireDo you get alerts before your contracts expire
Do you get alerts before your contracts expirePractice-League
 
The Microsoft platform for education analytics (mpea)
The Microsoft platform for education analytics (mpea)The Microsoft platform for education analytics (mpea)
The Microsoft platform for education analytics (mpea)Willy Marroquin (WillyDevNET)
 
8 Places to use Keywords on Your Website
8 Places to use Keywords on Your Website8 Places to use Keywords on Your Website
8 Places to use Keywords on Your WebsiteWired Flare
 
Redbrick safety sneakers Redbrick veiligheidsschoenen - werkschoenen by woltex
Redbrick safety sneakers Redbrick veiligheidsschoenen - werkschoenen by woltexRedbrick safety sneakers Redbrick veiligheidsschoenen - werkschoenen by woltex
Redbrick safety sneakers Redbrick veiligheidsschoenen - werkschoenen by woltexWoltex.nl
 
9 claves de la Ley de Cestaticket Socialista
9 claves de la Ley de Cestaticket Socialista9 claves de la Ley de Cestaticket Socialista
9 claves de la Ley de Cestaticket SocialistaNayma Consultores
 
Patterson Boulevard Canal Parkway - Before and After
Patterson Boulevard Canal Parkway - Before and AfterPatterson Boulevard Canal Parkway - Before and After
Patterson Boulevard Canal Parkway - Before and AfterCity of Dayton
 
Чат боты как пробный, коммуникационный, шар ии на пути иичу
Чат боты как пробный, коммуникационный, шар ии на пути иичуЧат боты как пробный, коммуникационный, шар ии на пути иичу
Чат боты как пробный, коммуникационный, шар ии на пути иичуSergey Skabelkin
 
APPRAISAL OF GROUND WATER CHARACTERISTICS AND WATER QUALITY INDEX OF RICH IRO...
APPRAISAL OF GROUND WATER CHARACTERISTICS AND WATER QUALITY INDEX OF RICH IRO...APPRAISAL OF GROUND WATER CHARACTERISTICS AND WATER QUALITY INDEX OF RICH IRO...
APPRAISAL OF GROUND WATER CHARACTERISTICS AND WATER QUALITY INDEX OF RICH IRO...AM Publications
 

Andere mochten auch (13)

Functional testing the_good_the_bad_and_the_ugly
Functional testing the_good_the_bad_and_the_uglyFunctional testing the_good_the_bad_and_the_ugly
Functional testing the_good_the_bad_and_the_ugly
 
Sildeshare
SildeshareSildeshare
Sildeshare
 
Do you get alerts before your contracts expire
Do you get alerts before your contracts expireDo you get alerts before your contracts expire
Do you get alerts before your contracts expire
 
The Microsoft platform for education analytics (mpea)
The Microsoft platform for education analytics (mpea)The Microsoft platform for education analytics (mpea)
The Microsoft platform for education analytics (mpea)
 
8 Places to use Keywords on Your Website
8 Places to use Keywords on Your Website8 Places to use Keywords on Your Website
8 Places to use Keywords on Your Website
 
Smallbizhouston Company Ppt
Smallbizhouston Company PptSmallbizhouston Company Ppt
Smallbizhouston Company Ppt
 
Redbrick safety sneakers Redbrick veiligheidsschoenen - werkschoenen by woltex
Redbrick safety sneakers Redbrick veiligheidsschoenen - werkschoenen by woltexRedbrick safety sneakers Redbrick veiligheidsschoenen - werkschoenen by woltex
Redbrick safety sneakers Redbrick veiligheidsschoenen - werkschoenen by woltex
 
9 claves de la Ley de Cestaticket Socialista
9 claves de la Ley de Cestaticket Socialista9 claves de la Ley de Cestaticket Socialista
9 claves de la Ley de Cestaticket Socialista
 
Philanthropic Curve
Philanthropic CurvePhilanthropic Curve
Philanthropic Curve
 
Patterson Boulevard Canal Parkway - Before and After
Patterson Boulevard Canal Parkway - Before and AfterPatterson Boulevard Canal Parkway - Before and After
Patterson Boulevard Canal Parkway - Before and After
 
Castañeda y ppk
Castañeda y ppkCastañeda y ppk
Castañeda y ppk
 
Чат боты как пробный, коммуникационный, шар ии на пути иичу
Чат боты как пробный, коммуникационный, шар ии на пути иичуЧат боты как пробный, коммуникационный, шар ии на пути иичу
Чат боты как пробный, коммуникационный, шар ии на пути иичу
 
APPRAISAL OF GROUND WATER CHARACTERISTICS AND WATER QUALITY INDEX OF RICH IRO...
APPRAISAL OF GROUND WATER CHARACTERISTICS AND WATER QUALITY INDEX OF RICH IRO...APPRAISAL OF GROUND WATER CHARACTERISTICS AND WATER QUALITY INDEX OF RICH IRO...
APPRAISAL OF GROUND WATER CHARACTERISTICS AND WATER QUALITY INDEX OF RICH IRO...
 

Ähnlich wie Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)

Nitro for your Grails App: how to improve performance. Greach '18
Nitro for your Grails App: how to improve performance. Greach '18Nitro for your Grails App: how to improve performance. Greach '18
Nitro for your Grails App: how to improve performance. Greach '18Alberto De Ávila Hernández
 
Nitro for your Grails App: How to improve performance!! Greach' 18
Nitro for your Grails App: How to improve performance!!  Greach' 18Nitro for your Grails App: How to improve performance!!  Greach' 18
Nitro for your Grails App: How to improve performance!! Greach' 18Alberto Barón Cuevas
 
Greach 18: JavaMelody to measure Grails app performance
Greach 18: JavaMelody to measure Grails app performanceGreach 18: JavaMelody to measure Grails app performance
Greach 18: JavaMelody to measure Grails app performanceMiguel Ángel García Gómez
 
#Interactive Session by Nikhil Jain, "Catch All Mail With Graph" at #ATAGTR2023.
#Interactive Session by Nikhil Jain, "Catch All Mail With Graph" at #ATAGTR2023.#Interactive Session by Nikhil Jain, "Catch All Mail With Graph" at #ATAGTR2023.
#Interactive Session by Nikhil Jain, "Catch All Mail With Graph" at #ATAGTR2023.Agile Testing Alliance
 
React and GraphQL at Stripe
React and GraphQL at StripeReact and GraphQL at Stripe
React and GraphQL at StripeSashko Stubailo
 
#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange
#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange
#FunLearnSeason2 - Talk 2 : Publishing your App on AppexchangeSikha Baid ☁
 
Build a production ready PWA - LINKIT & KLM Digital Studio Meetup
Build a production ready PWA - LINKIT & KLM Digital Studio MeetupBuild a production ready PWA - LINKIT & KLM Digital Studio Meetup
Build a production ready PWA - LINKIT & KLM Digital Studio MeetupÖnder Ceylan
 
JDD 2016 - Bartosz Majsak - Meet The Assertable Chaos Monkeys
JDD 2016 - Bartosz Majsak - Meet The Assertable Chaos Monkeys JDD 2016 - Bartosz Majsak - Meet The Assertable Chaos Monkeys
JDD 2016 - Bartosz Majsak - Meet The Assertable Chaos Monkeys PROIDEA
 
Java Puzzlers NG S02: Down the Rabbit Hole as presented at DevNexus 2017
Java Puzzlers NG S02: Down the Rabbit Hole as presented at DevNexus 2017Java Puzzlers NG S02: Down the Rabbit Hole as presented at DevNexus 2017
Java Puzzlers NG S02: Down the Rabbit Hole as presented at DevNexus 2017Baruch Sadogursky
 
Controlling Technical Debt with Continuous Delivery
Controlling Technical Debt with Continuous DeliveryControlling Technical Debt with Continuous Delivery
Controlling Technical Debt with Continuous Deliverywalkmod
 
Feedback en continu grâce au TDD et au AsCode
Feedback en continu grâce au TDD et au AsCodeFeedback en continu grâce au TDD et au AsCode
Feedback en continu grâce au TDD et au AsCodeHaja R
 
Continuous Delivery As Code
Continuous Delivery As CodeContinuous Delivery As Code
Continuous Delivery As CodeAlex Soto
 
Build a production ready PWA with Angular and Firebase
Build a production ready PWA with Angular and FirebaseBuild a production ready PWA with Angular and Firebase
Build a production ready PWA with Angular and FirebaseÖnder Ceylan
 
Angular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of SpeedAngular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of SpeedIlia Idakiev
 
Developer Tests - Things to Know
Developer Tests - Things to KnowDeveloper Tests - Things to Know
Developer Tests - Things to KnowVaidas Pilkauskas
 

Ähnlich wie Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional) (20)

Nitro for your Grails App: how to improve performance. Greach '18
Nitro for your Grails App: how to improve performance. Greach '18Nitro for your Grails App: how to improve performance. Greach '18
Nitro for your Grails App: how to improve performance. Greach '18
 
Nitro for your Grails App: How to improve performance!! Greach' 18
Nitro for your Grails App: How to improve performance!!  Greach' 18Nitro for your Grails App: How to improve performance!!  Greach' 18
Nitro for your Grails App: How to improve performance!! Greach' 18
 
Graalvm with Groovy and Kotlin - Greach 2019
Graalvm with Groovy and Kotlin - Greach 2019Graalvm with Groovy and Kotlin - Greach 2019
Graalvm with Groovy and Kotlin - Greach 2019
 
Let Codenarc check if you write good Groovy code
Let Codenarc check if you write good Groovy codeLet Codenarc check if you write good Groovy code
Let Codenarc check if you write good Groovy code
 
Graalvm with Groovy and Kotlin - Madrid GUG 2019
Graalvm with Groovy and Kotlin - Madrid GUG 2019Graalvm with Groovy and Kotlin - Madrid GUG 2019
Graalvm with Groovy and Kotlin - Madrid GUG 2019
 
Greach 18: JavaMelody to measure Grails app performance
Greach 18: JavaMelody to measure Grails app performanceGreach 18: JavaMelody to measure Grails app performance
Greach 18: JavaMelody to measure Grails app performance
 
#Interactive Session by Nikhil Jain, "Catch All Mail With Graph" at #ATAGTR2023.
#Interactive Session by Nikhil Jain, "Catch All Mail With Graph" at #ATAGTR2023.#Interactive Session by Nikhil Jain, "Catch All Mail With Graph" at #ATAGTR2023.
#Interactive Session by Nikhil Jain, "Catch All Mail With Graph" at #ATAGTR2023.
 
Meteor WWNRW Intro
Meteor WWNRW IntroMeteor WWNRW Intro
Meteor WWNRW Intro
 
React and GraphQL at Stripe
React and GraphQL at StripeReact and GraphQL at Stripe
React and GraphQL at Stripe
 
#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange
#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange
#FunLearnSeason2 - Talk 2 : Publishing your App on Appexchange
 
Build a production ready PWA - LINKIT & KLM Digital Studio Meetup
Build a production ready PWA - LINKIT & KLM Digital Studio MeetupBuild a production ready PWA - LINKIT & KLM Digital Studio Meetup
Build a production ready PWA - LINKIT & KLM Digital Studio Meetup
 
JDD 2016 - Bartosz Majsak - Meet The Assertable Chaos Monkeys
JDD 2016 - Bartosz Majsak - Meet The Assertable Chaos Monkeys JDD 2016 - Bartosz Majsak - Meet The Assertable Chaos Monkeys
JDD 2016 - Bartosz Majsak - Meet The Assertable Chaos Monkeys
 
Spring Cloud’s Groovy
Spring Cloud’s GroovySpring Cloud’s Groovy
Spring Cloud’s Groovy
 
Java Puzzlers NG S02: Down the Rabbit Hole as presented at DevNexus 2017
Java Puzzlers NG S02: Down the Rabbit Hole as presented at DevNexus 2017Java Puzzlers NG S02: Down the Rabbit Hole as presented at DevNexus 2017
Java Puzzlers NG S02: Down the Rabbit Hole as presented at DevNexus 2017
 
Controlling Technical Debt with Continuous Delivery
Controlling Technical Debt with Continuous DeliveryControlling Technical Debt with Continuous Delivery
Controlling Technical Debt with Continuous Delivery
 
Feedback en continu grâce au TDD et au AsCode
Feedback en continu grâce au TDD et au AsCodeFeedback en continu grâce au TDD et au AsCode
Feedback en continu grâce au TDD et au AsCode
 
Continuous Delivery As Code
Continuous Delivery As CodeContinuous Delivery As Code
Continuous Delivery As Code
 
Build a production ready PWA with Angular and Firebase
Build a production ready PWA with Angular and FirebaseBuild a production ready PWA with Angular and Firebase
Build a production ready PWA with Angular and Firebase
 
Angular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of SpeedAngular server side rendering with NodeJS - In Pursuit Of Speed
Angular server side rendering with NodeJS - In Pursuit Of Speed
 
Developer Tests - Things to Know
Developer Tests - Things to KnowDeveloper Tests - Things to Know
Developer Tests - Things to Know
 

Kürzlich hochgeladen

Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical EngineeringC Sai Kiran
 
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...Amil baba
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2T.D. Shashikala
 
ENCODERS & DECODERS - Digital Electronics - diu swe
ENCODERS & DECODERS - Digital Electronics - diu sweENCODERS & DECODERS - Digital Electronics - diu swe
ENCODERS & DECODERS - Digital Electronics - diu sweMohammadAliNayeem
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfAyahmorsy
 
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5T.D. Shashikala
 
internship exam ppt.pptx on embedded system and IOT
internship exam ppt.pptx on embedded system and IOTinternship exam ppt.pptx on embedded system and IOT
internship exam ppt.pptx on embedded system and IOTNavyashreeS6
 
Low rpm Generator for efficient energy harnessing from a two stage wind turbine
Low rpm Generator for efficient energy harnessing from a two stage wind turbineLow rpm Generator for efficient energy harnessing from a two stage wind turbine
Low rpm Generator for efficient energy harnessing from a two stage wind turbineAftabkhan575376
 
Attraction and Repulsion type Moving Iron Instruments.pptx
Attraction and Repulsion type Moving Iron Instruments.pptxAttraction and Repulsion type Moving Iron Instruments.pptx
Attraction and Repulsion type Moving Iron Instruments.pptxkarthikeyanS725446
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfKamal Acharya
 
Lect 2 - Design of slender column-2.pptx
Lect 2 - Design of slender column-2.pptxLect 2 - Design of slender column-2.pptx
Lect 2 - Design of slender column-2.pptxHamzaKhawar4
 
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamKIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamDr. Radhey Shyam
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationDr. Radhey Shyam
 
Electrical shop management system project report.pdf
Electrical shop management system project report.pdfElectrical shop management system project report.pdf
Electrical shop management system project report.pdfKamal Acharya
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.MdManikurRahman
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxwendy cai
 
Electrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineElectrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineJulioCesarSalazarHer1
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdfKamal Acharya
 
Lect_Z_Transform_Main_digital_image_processing.pptx
Lect_Z_Transform_Main_digital_image_processing.pptxLect_Z_Transform_Main_digital_image_processing.pptx
Lect_Z_Transform_Main_digital_image_processing.pptxMonirHossain707319
 
Paint shop management system project report.pdf
Paint shop management system project report.pdfPaint shop management system project report.pdf
Paint shop management system project report.pdfKamal Acharya
 

Kürzlich hochgeladen (20)

Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical EngineeringIntroduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
Introduction to Machine Learning Unit-4 Notes for II-II Mechanical Engineering
 
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
NO1 Pandit Black Magic Removal in Uk kala jadu Specialist kala jadu for Love ...
 
Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2Research Methodolgy & Intellectual Property Rights Series 2
Research Methodolgy & Intellectual Property Rights Series 2
 
ENCODERS & DECODERS - Digital Electronics - diu swe
ENCODERS & DECODERS - Digital Electronics - diu sweENCODERS & DECODERS - Digital Electronics - diu swe
ENCODERS & DECODERS - Digital Electronics - diu swe
 
Peek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdfPeek implant persentation - Copy (1).pdf
Peek implant persentation - Copy (1).pdf
 
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
RM&IPR M5 notes.pdfResearch Methodolgy & Intellectual Property Rights Series 5
 
internship exam ppt.pptx on embedded system and IOT
internship exam ppt.pptx on embedded system and IOTinternship exam ppt.pptx on embedded system and IOT
internship exam ppt.pptx on embedded system and IOT
 
Low rpm Generator for efficient energy harnessing from a two stage wind turbine
Low rpm Generator for efficient energy harnessing from a two stage wind turbineLow rpm Generator for efficient energy harnessing from a two stage wind turbine
Low rpm Generator for efficient energy harnessing from a two stage wind turbine
 
Attraction and Repulsion type Moving Iron Instruments.pptx
Attraction and Repulsion type Moving Iron Instruments.pptxAttraction and Repulsion type Moving Iron Instruments.pptx
Attraction and Repulsion type Moving Iron Instruments.pptx
 
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdfONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
ONLINE VEHICLE RENTAL SYSTEM PROJECT REPORT.pdf
 
Lect 2 - Design of slender column-2.pptx
Lect 2 - Design of slender column-2.pptxLect 2 - Design of slender column-2.pptx
Lect 2 - Design of slender column-2.pptx
 
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data StreamKIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
KIT-601 Lecture Notes-UNIT-3.pdf Mining Data Stream
 
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and VisualizationKIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
KIT-601 Lecture Notes-UNIT-5.pdf Frame Works and Visualization
 
Electrical shop management system project report.pdf
Electrical shop management system project report.pdfElectrical shop management system project report.pdf
Electrical shop management system project report.pdf
 
"United Nations Park" Site Visit Report.
"United Nations Park" Site  Visit Report."United Nations Park" Site  Visit Report.
"United Nations Park" Site Visit Report.
 
Construction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptxConstruction method of steel structure space frame .pptx
Construction method of steel structure space frame .pptx
 
Electrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission lineElectrostatic field in a coaxial transmission line
Electrostatic field in a coaxial transmission line
 
Laundry management system project report.pdf
Laundry management system project report.pdfLaundry management system project report.pdf
Laundry management system project report.pdf
 
Lect_Z_Transform_Main_digital_image_processing.pptx
Lect_Z_Transform_Main_digital_image_processing.pptxLect_Z_Transform_Main_digital_image_processing.pptx
Lect_Z_Transform_Main_digital_image_processing.pptx
 
Paint shop management system project report.pdf
Paint shop management system project report.pdfPaint shop management system project report.pdf
Paint shop management system project report.pdf
 

Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)

  • 1. Salenda Testing Grails 3: the good (unit), the bad (integration) and the ugly (functional) Greach ’17 Alberto De Ávila Hernández
  • 2. A B O U T M E ✴ Software Engineer ✴ Team Lead at Salenda ✴ Groovy y Grails dev ✴ Testing obsessed @alberto_deavila
  • 3. S A L E N D A
  • 4. S O F T WA R E D E V E L O P M E N T Turnkey development Gold Atlassian Solution Partner Consulting and support in software architecture and analysis Application integration Evolutionary support of our own developments or inherited ones @alberto_deavila
  • 5. O B J E C T I V E S @alberto_deavila Objectives
  • 6. F I R S T S T E P S @alberto_deavila First Steps
  • 7. F I R S T S T E P S @alberto_deavila ✴ Install Java 8 ✴ Install sdkman >$ curl -s "https://get.sdkman.io" | bash >$ source "$HOME/.sdkman/bin/sdkman-init.sh" ✴ Install Grails 3.2.6 >$ sdk install grails 3.2.6 ✴Clone: github.com/albertodeavila/testingGrails3
  • 8. G U I D E @alberto_deavila ✴ Testing types ✴ Testing in Grails 3 ✴ Review app ✴ Unit testing ✴ Functional testing ✴ Integration testing
  • 9. T E S T I N G T Y P E S @alberto_deavila Testing types
  • 10. T E S T I N G T Y P E S @alberto_deavila Unit (the good)
  • 11. T E S T I N G T Y P E S : U N I T @alberto_deavila ✴ Test a small piece of code ✴ Simulate the rest of pieces ✴ Mock it ✴ Override behavior ✴ Independents on the environment ✴ Very quickly
  • 12. T E S T I N G T Y P E S @alberto_deavila Integration (the bad)
  • 13. T E S T I N G T Y P E S : I N T E G R AT I O N @alberto_deavila ✴ Test a complete functionality ✴ Start the app ✴ Test inside the app ✴ Slow ✴ Depends on the environment
  • 14. T E S T I N G T Y P E S @alberto_deavila Functional (the ugly)
  • 15. T E S T I N G T Y P E S : F U N C T I O N A L @alberto_deavila ✴ Test a complete functionality as a user ✴ Start the app ✴ Test outside the app ✴ Browsing the app / calling API ✴ Slow ✴ Not cross browser and some browser errors
  • 16. T E S T I N G I N G R A I L S 3 @alberto_deavila Testing in Grails 3
  • 17. T E S T I N G I N G R A I L S 3 @alberto_deavila ✴ Plugins: ✴ Build test-data plugin ✴ Greenmail ✴ Rest client builder ✴ Spock ✴ Geb
  • 18. T E S T I N G I N G R A I L S 3 : S P O C K @alberto_deavila Spock
  • 19. T E S T I N G I N G R A I L S 3 : S P O C K @alberto_deavila ✴ Describe test ✴ Blocks ✴ Mocks ✴ Data tables ✴ Fixture methods ✴ Tricks and recomendations
  • 20. T E S T I N G I N G R A I L S 3 : S P O C K @alberto_deavila Describe test
  • 21. T E S T I N G I N G R A I L S 3 : S P O C K @alberto_deavila ✴ Given / Setup: preconditions and data ✴ Cleanup: postconditions ✴ When: action that trigger some outcome ✴ Then / Expect: assert outcome ✴ Where: applies varied data Blocks
  • 22. T E S T I N G I N G R A I L S 3 : S P O C K @alberto_deavila ✴ Given, Expect ✴ Given, When, Then ✴ Given, When, Then, Where, Cleanup ✴ Given, Expect, Where ✴ When, Then, Where, Cleanup Blocks: samples
  • 23. T E S T I N G I N G R A I L S 3 : S P O C K @alberto_deavila Mocks Data tables
  • 24. T E S T I N G I N G R A I L S 3 : S P O C K @alberto_deavila Fixture methods
  • 25. T E S T I N G I N G R A I L S 3 : S P O C K @alberto_deavila ✴ Use assert if there are { } in then clause ✴ You can catch exceptions with thrown ✴ @Build includes @Mock ✴ Use .buildWithoutSave() to avoid persist ✴ Use @ConfineMetaClassChanges ;) Tricks & recommendations
  • 26. R E V I E W A P P @alberto_deavila Review app
  • 27. L E T ’ S G O T E S T @alberto_deavila Let’s go test!
  • 28. U N I T T E S T I N G @alberto_deavila Unit testing
  • 29. U N I T T E S T I N G @alberto_deavila ✴ Unit test extends Specification ✴ @TestFor annotation to indicate what test ✴ @Mock annotation to simulate another entity ✴ @Build annotation to create default entities
  • 30. U N I T T E S T I N G @alberto_deavila Domain classes
  • 31. U N I T T E S T I N G : D O M A I N C L A S S E S @alberto_deavila ✴ @TestFor with the domain class to test ✴ Check constraints and logic in domain class ✴ Implicit variable domain ✴ Tricks: ✴ Use the @Unroll to use different data ✴ Persistence can’t be tested with unit test
  • 32. U N I T T E S T I N G : D O M A I N C L A S S E S @alberto_deavila Example: EpisodeUnitSpec
  • 33. U N I T T E S T I N G : D O M A I N C L A S S E S @alberto_deavila Exercise: SerieUnitSpec
  • 34. U N I T T E S T I N G @alberto_deavila Services
  • 35. U N I T T E S T I N G : S E R V I C E S @alberto_deavila ✴ Again @TestFor annotation ✴ Implicit variable service ✴ defineBeans: to inject services / beans ✴ Override method: ✴ Metaclass ✴ Mock
  • 36. U N I T T E S T I N G : S E R V I C E S @alberto_deavila Example: ActorServiceUnitSpec
  • 37. U N I T T E S T I N G : S E R V I C E S @alberto_deavila Exercise: SerieServiceUnitSpec
  • 38. U N I T T E S T I N G @alberto_deavila Controllers
  • 39. U N I T T E S T I N G : C O N T R O L L E R S @alberto_deavila ✴ Implicit variable controller ✴ Helpers: view / model / response ✴ defineBeans: to inject services / beans ✴ If action return a map, model & view are null ✴ Save the action call return in a variable ✴ Bug: view doesn’t contains the template
  • 40. U N I T T E S T I N G : C O N T R O L L E R S @alberto_deavila Example: UserControllerUnitSpec
  • 41. U N I T T E S T I N G : C O N T R O L L E R S @alberto_deavila Exercise: ActorControllerUnitSpec
  • 42. U N I T T E S T I N G : C O N T R O L L E R S @alberto_deavila Exercise: SerieControllerUnitSpec
  • 43. F U N C T I O N A L T E S T I N G @alberto_deavila Functional testing
  • 44. F U N C T I O N A L T E S T I N G @alberto_deavila API
  • 45. F U N C T I O N A L T E S T I N G @alberto_deavila ✴ To test APIs you can use RestBuilder ✴ Use authentication ✴ Parse JSON / XML responses
  • 46. F U N C T I O N A L T E S T I N G @alberto_deavila Example: UserAPIFunctionalSpec
  • 47. T E S T I N G I N G R A I L S 3 : G E B @alberto_deavila
  • 48. T E S T I N G I N G R A I L S 3 : G E B @alberto_deavila ✴ Define: ✴ Pages: elements with jQuery style selectors ✴ Modules: reuse content ✴ Create test to navigate through app ✴ Check content visible in browser
  • 49. T E S T I N G I N G R A I L S 3 : G E B @alberto_deavila Pages
  • 50. T E S T I N G I N G R A I L S 3 : G E B @alberto_deavila Test
  • 51. F U N C T I O N A L T E S T I N G @alberto_deavila ✴ Functional test extends GebSpec ✴ You can use beans with @Autowired ✴ To create data: Entity.withNewSession ✴ @Stepwise to execute test depending on the previous
  • 52. F U N C T I O N A L T E S T I N G @alberto_deavila ✴ To execute JS code: js.exec(“alert(‘hi’)“) ✴ Go to some URL with: go(URL) ✴ Go to some Page defined: to SomePage ✴ Check if we are at a Page: at SomePage ✴ Use waitFor to ensure content is loaded ✴ To define Optional content: (required: false)
  • 53. U N I T T E S T I N G : C O N T R O L L E R S @alberto_deavila Example: UserFunctionalSpec
  • 54. U N I T T E S T I N G : C O N T R O L L E R S @alberto_deavila Exercise: SerieFunctionalSpec
  • 55. I N T E G R AT I O N T E S T I N G @alberto_deavila Integration testing
  • 56. I N T E G R AT I O N T E S T I N G @alberto_deavila ✴ Functional test extends Specification ✴ Mark @Integration to differentiate from unit ✴ Like functional: use services with @Autowired ✴ You don’t need to use @Build annotation
  • 57. I N T E G R AT I O N T E S T I N G @alberto_deavila Domain classes
  • 58. I N T E G R AT I O N T E S T I N G : D O M A I N C L A S S E S @alberto_deavila ✴ Very similar to unit test ✴ You don’t need to mock domain classes :) ✴ You can check database persistence and integrity ✴ Remember to Delete your created data or use @Rollback
  • 59. I N T E G R AT I O N T E S T I N G : D O M A I N C L A S S E S @alberto_deavila Example: UserIntegrationSpec
  • 60. I N T E G R AT I O N T E S T I N G : D O M A I N C L A S S E S @alberto_deavila Exercise: EpisodeIntegrationSpec
  • 61. I N T E G R AT I O N T E S T I N G @alberto_deavila Services
  • 62. I N T E G R AT I O N T E S T I N G : S E R V I C E S @alberto_deavila ✴ Define services with @Autowired ✴ Use it ;)
  • 63. I N T E G R AT I O N T E S T I N G : S E R V I C E S @alberto_deavila Example: SerieServiceIntegrationSpec
  • 64. I N T E G R AT I O N T E S T I N G : S E R V I C E S @alberto_deavila Exercise: UserServiceIntegrationSpec
  • 65. I N T E G R AT I O N T E S T I N G @alberto_deavila Controllers
  • 66. I N T E G R AT I O N T E S T I N G : C O N T R O L L E R S @alberto_deavila Grails docs: “To integration test controllers it is recommended you use create-functional-test command to create a Geb functional test.”
  • 67. I N T E G R AT I O N T E S T I N G : C O N T R O L L E R S @alberto_deavila ✴ @Autowire Controller instance ✴ Define a bean WebApplicationContext ✴ To allow make request GrailsWebMockUtil. bindMockWebRequest (context)
  • 68. I N T E G R AT I O N T E S T I N G : C O N T R O L L E R S @alberto_deavila ✴If action make redirect, ensure you have controller specified ✴ Use modelAndView to obtain ✴ View name ✴ Renderer data
  • 69. I N T E G R AT I O N T E S T I N G : C O N T R O L L E R S @alberto_deavila Example: SerieControllerIntegrationSpec
  • 70. I N T E G R AT I O N T E S T I N G : C O N T R O L L E R S @alberto_deavila Exercise: UserControllerIntegrationSpec
  • 71. Q U E S T I O N S @alberto_deavila That’s all!Thank you!!
  • 72. Q U E S T I O N S @alberto_deavila Questions