testing grails 3, the goob (unit), the bad (integration) and the ugly (functional)
TRANSCRIPT
![Page 1: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/1.jpg)
SalendaTesting Grails 3:
the good (unit), the bad (integration) and the ugly (functional)
Greach ’17
Alberto De Ávila Hernández
![Page 2: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/2.jpg)
A B O U T M E
✴ Software Engineer
✴ Team Lead at Salenda
✴ Groovy y Grails dev
✴ Testing obsessed
@alberto_deavila
![Page 3: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/3.jpg)
S A L E N D A
![Page 4: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/4.jpg)
S O F T W A 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
![Page 5: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/5.jpg)
O B J E C T I V E S
@alberto_deavila
Objectives
![Page 6: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/6.jpg)
F I R S T S T E P S
@alberto_deavila
First Steps
![Page 7: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/7.jpg)
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
![Page 8: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/8.jpg)
G U I D E
@alberto_deavila
✴ Testing types
✴ Testing in Grails 3
✴ Review app
✴ Unit testing
✴ Functional testing
✴ Integration testing
![Page 9: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/9.jpg)
T E S T I N G T Y P E S
@alberto_deavila
Testing types
![Page 10: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/10.jpg)
T E S T I N G T Y P E S
@alberto_deavila
Unit (the good)
![Page 11: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/11.jpg)
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
![Page 12: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/12.jpg)
T E S T I N G T Y P E S
@alberto_deavila
Integration (the bad)
![Page 13: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/13.jpg)
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
![Page 14: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/14.jpg)
T E S T I N G T Y P E S
@alberto_deavila
Functional (the ugly)
![Page 15: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/15.jpg)
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
![Page 16: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/16.jpg)
T E S T I N G I N G R A I L S 3
@alberto_deavila
Testing in Grails 3
![Page 17: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/17.jpg)
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
![Page 18: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/18.jpg)
T E S T I N G I N G R A I L S 3 : S P O C K
@alberto_deavila
Spock
![Page 19: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/19.jpg)
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
![Page 20: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/20.jpg)
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
![Page 21: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/21.jpg)
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
![Page 22: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/22.jpg)
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
![Page 23: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/23.jpg)
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
![Page 24: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/24.jpg)
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
![Page 25: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/25.jpg)
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
![Page 26: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/26.jpg)
R E V I E W A P P
@alberto_deavila
Review app
![Page 27: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/27.jpg)
L E T ’ S G O T E S T
@alberto_deavila
Let’s go test!
![Page 28: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/28.jpg)
U N I T T E S T I N G
@alberto_deavila
Unit testing
![Page 29: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/29.jpg)
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
![Page 30: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/30.jpg)
U N I T T E S T I N G
@alberto_deavila
Domain classes
![Page 31: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/31.jpg)
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
![Page 32: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/32.jpg)
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
![Page 33: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/33.jpg)
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
![Page 34: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/34.jpg)
U N I T T E S T I N G
@alberto_deavila
Services
![Page 35: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/35.jpg)
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
![Page 36: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/36.jpg)
U N I T T E S T I N G : S E R V I C E S
@alberto_deavila
Example:
ActorServiceUnitSpec
![Page 37: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/37.jpg)
U N I T T E S T I N G : S E R V I C E S
@alberto_deavila
Exercise:
SerieServiceUnitSpec
![Page 38: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/38.jpg)
U N I T T E S T I N G
@alberto_deavila
Controllers
![Page 39: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/39.jpg)
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
![Page 40: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/40.jpg)
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
![Page 41: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/41.jpg)
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
![Page 42: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/42.jpg)
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
![Page 43: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/43.jpg)
F U N C T I O N A L T E S T I N G
@alberto_deavila
Functional testing
![Page 44: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/44.jpg)
F U N C T I O N A L T E S T I N G
@alberto_deavila
API
![Page 45: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/45.jpg)
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
![Page 46: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/46.jpg)
F U N C T I O N A L T E S T I N G
@alberto_deavila
Example:
UserAPIFunctionalSpec
![Page 47: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/47.jpg)
T E S T I N G I N G R A I L S 3 : G E B
@alberto_deavila
![Page 48: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/48.jpg)
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
![Page 49: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/49.jpg)
T E S T I N G I N G R A I L S 3 : G E B
@alberto_deavila
Pages
![Page 50: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/50.jpg)
T E S T I N G I N G R A I L S 3 : G E B
@alberto_deavila
Test
![Page 51: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/51.jpg)
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
![Page 52: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/52.jpg)
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)
![Page 53: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/53.jpg)
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
![Page 54: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/54.jpg)
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
![Page 55: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/55.jpg)
I N T E G R AT I O N T E S T I N G
@alberto_deavila
Integration testing
![Page 56: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/56.jpg)
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
![Page 57: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/57.jpg)
I N T E G R AT I O N T E S T I N G
@alberto_deavila
Domain classes
![Page 58: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/58.jpg)
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
![Page 59: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/59.jpg)
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
![Page 60: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/60.jpg)
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
![Page 61: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/61.jpg)
I N T E G R AT I O N T E S T I N G
@alberto_deavila
Services
![Page 62: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/62.jpg)
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 ;)
![Page 63: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/63.jpg)
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
![Page 64: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/64.jpg)
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
![Page 65: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/65.jpg)
I N T E G R AT I O N T E S T I N G
@alberto_deavila
Controllers
![Page 66: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/66.jpg)
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.”
![Page 67: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/67.jpg)
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)
![Page 68: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/68.jpg)
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
![Page 69: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/69.jpg)
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
![Page 70: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/70.jpg)
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
![Page 71: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/71.jpg)
Q U E S T I O N S
@alberto_deavila
That’s all!Thank you!!
![Page 72: Testing Grails 3, the goob (unit), the bad (integration) and the ugly (functional)](https://reader036.vdocuments.mx/reader036/viewer/2022081511/58f9ad1f760da3da068b950f/html5/thumbnails/72.jpg)
Q U E S T I O N S
@alberto_deavila
Questions