First things first• Mario García •   Freelance •   Happily working with Grails every day •   Blamed for a felony I didn’t ...
What is this about? because we don’t need to test...do we?
What is this about?    WE ARE      NOT    PERFECT
When do we realize?      WTF!!
Why I test?• Do they make me flawless?   Nop, In fact they remind me every day                how bad I am• Do they avoid ...
Sample Code• https://github.com/mariogarcia/maroulette
Integration Tests     Why first???
Why first?• ... because you do all your important stuff in  services, Don’t you MTF?
What to test?• External systems integration:  •   Database  •   Web-services / Rest  •   Queue system  •   ...
Weapons• Grails “inbuilt” integration tests• 2.0.x > * Interactive mode & Guard Plugin• Spock• Fixtures• Build Test Data
Grails Integration Tests• By default• JUnit Based• The application is “UP AND RUNNING”• Use the interactive mode to save t...
Plugins• Spock • More natural way of writing tests • Parameter tables ROCKS!!! • Helps you to document!!!
Plugins• Fixtures Plugin •   We can create common testing datasets• Build Test Data Plugin •   Sometimes we don’t care abo...
Plugins• Spock: http://grails.org/plugin/spock• Fixtures: http://grails.org/plugin/spock• Build Test Data:       http://gr...
Grails Integration Tests
Unit Testing  The easiest one?
Usual Suspects• Controllers• Taglibs• UrlMappings• Filters• Other silly things...
Typical Case• Testing a controller •   What the output view is gonna be if       •   everything went ok ?       •   everyt...
Weapons•   Grails Mocking    •   Don’t test controllers with real services    •   Use Mixins instead to simulate them    •...
Weapons• Spock Tables to the rescue!!! •   Natural way of doing use cases in your     controllers
Grails Unit Testing
Functional Testing Is it working as the user expected?           Game Over!
Functional testing• Plugins • Functional Testing   •   http://www.grails.org/plugin/functional-test • Geb   •   http://www...
Functional Testing
Please, don’t hate JS      it’s cute, isn’t it?
Testing JS    •   http://grails.org/plugin/jasmine    •   http://grails.org/plugin/angularjs-resources•   casperjs    •   ...
Q&AAsk now or be quiet forever!!!
Test Motherfucker...Test
Upcoming SlideShare
Loading in …5
×

Test Motherfucker...Test

1,495 views

Published on

Slides from

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,495
On SlideShare
0
From Embeds
0
Number of Embeds
181
Actions
Shares
0
Downloads
12
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Test Motherfucker...Test

  1. 1. First things first• Mario García • Freelance • Happily working with Grails every day • Blamed for a felony I didn’t commit I ran away to Ireland...still there!! marioggar desmontandojava.blogspot.com mariogarcia
  2. 2. What is this about? because we don’t need to test...do we?
  3. 3. What is this about? WE ARE NOT PERFECT
  4. 4. When do we realize? WTF!!
  5. 5. Why I test?• Do they make me flawless? Nop, In fact they remind me every day how bad I am• Do they avoid bugs?me to detect them Nop, but they help before is too late
  6. 6. Sample Code• https://github.com/mariogarcia/maroulette
  7. 7. Integration Tests Why first???
  8. 8. Why first?• ... because you do all your important stuff in services, Don’t you MTF?
  9. 9. What to test?• External systems integration: • Database • Web-services / Rest • Queue system • ...
  10. 10. Weapons• Grails “inbuilt” integration tests• 2.0.x > * Interactive mode & Guard Plugin• Spock• Fixtures• Build Test Data
  11. 11. Grails Integration Tests• By default• JUnit Based• The application is “UP AND RUNNING”• Use the interactive mode to save time
  12. 12. Plugins• Spock • More natural way of writing tests • Parameter tables ROCKS!!! • Helps you to document!!!
  13. 13. Plugins• Fixtures Plugin • We can create common testing datasets• Build Test Data Plugin • Sometimes we don’t care about field values • Just give me a valid persisted instance!!
  14. 14. Plugins• Spock: http://grails.org/plugin/spock• Fixtures: http://grails.org/plugin/spock• Build Test Data: http://grails.org/plugin/spock• Guard: http://grails.org/plugin/guard
  15. 15. Grails Integration Tests
  16. 16. Unit Testing The easiest one?
  17. 17. Usual Suspects• Controllers• Taglibs• UrlMappings• Filters• Other silly things...
  18. 18. Typical Case• Testing a controller • What the output view is gonna be if • everything went ok ? • everything went wrong ? • Should the user see any message? • Etc...
  19. 19. Weapons• Grails Mocking • Don’t test controllers with real services • Use Mixins instead to simulate them • Learn to create expectations
  20. 20. Weapons• Spock Tables to the rescue!!! • Natural way of doing use cases in your controllers
  21. 21. Grails Unit Testing
  22. 22. Functional Testing Is it working as the user expected? Game Over!
  23. 23. Functional testing• Plugins • Functional Testing • http://www.grails.org/plugin/functional-test • Geb • http://www.grails.org/plugin/geb
  24. 24. Functional Testing
  25. 25. Please, don’t hate JS it’s cute, isn’t it?
  26. 26. Testing JS • http://grails.org/plugin/jasmine • http://grails.org/plugin/angularjs-resources• casperjs • https://github.com/ulrich/grails-casper-plugin
  27. 27. Q&AAsk now or be quiet forever!!!

×