introducción al testing con grails (xpweek)
DESCRIPTION
Charla para la XPWeek el 23 de Septiembre de 2011TRANSCRIPT
![Page 1: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/1.jpg)
TESTING Y TDD CON GROOVY Y GRAILS
por Alberto Vilches http://albertovilches.com
Twitter: @albertovilches
![Page 2: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/2.jpg)
SOBRE MI
Pasado • Trabajando en desarrollo desde 1998 • Programador en Clipper y Delphi • Programador en Java y J2EE desde 2001 • Instructor y consultor de Bea • Administrador de sistemas en Aena Presente • Programador freelance en Grails y Flex • Partner de Escuela de Groovy • Evangelizador Groovy y Grails • Fundador de la conferencia Greach
![Page 3: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/3.jpg)
AGENDA
• Introducción a Groovy • Testing con Groovy
• Introducción a Grails • Testing con Grails
![Page 4: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/4.jpg)
¿QUÉ ES GROOVY?
• Groovy es Java • Dinámico • Inspirado en Ruby, Python y Smalltalk • OOP puro • Closures, Gstrings, Builders, DSL
![Page 5: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/5.jpg)
¿QUÉ ES GROOVY?
• Groovy es Java. • Dinámico • Inspirado en Ruby, Python y Smalltalk • OOP puro • Closures, Gstrings, Builders, DSL • No compile type-checking • Ligeramente más lento que Java
![Page 6: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/6.jpg)
TESTING CON GROOVY
• Power Asserts
• GroovyTestCase
• Mocking • Closure as OnlyOneMethodInterface • Map as Interface • Expando • mockFor / stubFor
![Page 7: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/7.jpg)
GROOVY POWER ASSERTS
![Page 8: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/8.jpg)
GROOVY TEST CASE
• Añade nuevos assert*
• Y algunos métodos como shouldFail o notImplementedYet
• Nombres de métodos largos
![Page 9: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/9.jpg)
MOCKING CON GROOVY
Closure as OnlyMethodInterface
![Page 10: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/10.jpg)
MOCKING CON GROOVY
Map as Interface
![Page 11: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/11.jpg)
MOCKING CON GROOVY
Expando
![Page 12: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/12.jpg)
MOCKING CON GROOVY
a
![Page 13: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/13.jpg)
MOCKING CON GROOVY
a
![Page 14: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/14.jpg)
MOCKING CON GROOVY
a
![Page 15: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/15.jpg)
MOCKING CON GROOVY
a
![Page 16: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/16.jpg)
GRAILS
• Introducción a Grails • Estructura de un proyecto • Artefactos
• Controladores • Objetos de dominio • Servicios
• Testing
![Page 17: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/17.jpg)
¿QUÉ ES GRAILS?
• Groovy sobre Spring • RAD en Java. Stack, no framework • CoC -> No XML • MVC (binding, i18n, validation) + persistencia • Servidor (Tomcat) y bbdd (HSQL) embebidos • Cambios en caliente, Genera WAR. • Extensible: plugins
![Page 18: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/18.jpg)
TESTING GRAILS
• Dinámico: código sensible vs fácil de testear • Mocks
• JUNIT • Pruebas unitarias • Pruebas de integración • Pruebas funcionales:
• Plugin: Selenium, Geb, Canoo Webtest
• Spock, GSpec, GMock
![Page 19: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/19.jpg)
ESTRUCTURA DEL PROYECTO
![Page 20: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/20.jpg)
VISIÓN GENERAL
CONTROLADORES
Uso directo
Inyección Spring
![Page 21: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/21.jpg)
VISIÓN GENERAL
CONTROLADORES
VISTAS
Uso directo
Inyección Spring
![Page 22: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/22.jpg)
VISIÓN GENERAL
CONTROLADORES
VISTAS
TAGLIBS
Uso directo
Inyección Spring
![Page 23: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/23.jpg)
VISIÓN GENERAL
CONTROLADORES
SERVICIOS
VISTAS
TAGLIBS
Uso directo
Inyección Spring
![Page 24: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/24.jpg)
VISIÓN GENERAL
CONTROLADORES
SERVICIOS
VISTAS
TAGLIBS
Uso directo
Inyección Spring
![Page 25: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/25.jpg)
VISIÓN GENERAL
CONTROLADORES
SERVICIOS
VISTAS
CLASES DE DOMINIO
TAGLIBS
Uso directo
Inyección Spring
![Page 26: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/26.jpg)
VISIÓN GENERAL
CONTROLADORES
SERVICIOS
VISTAS
CLASES DE DOMINIO
TAGLIBS
Uso directo
Inyección Spring
![Page 27: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/27.jpg)
MVC: CONTROLADORES
![Page 28: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/28.jpg)
MVC: CONTROLADORES
![Page 29: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/29.jpg)
MVC: CONTROLADORES
![Page 30: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/30.jpg)
MVC: CONTROLADORES
params session request response …
![Page 31: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/31.jpg)
MODELO DE DATOS: GORM
![Page 32: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/32.jpg)
MODELO DE DATOS: GORM
![Page 33: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/33.jpg)
MODELO DE DATOS: GORM
![Page 34: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/34.jpg)
MODELO DE DATOS: GORM
![Page 35: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/35.jpg)
MODELO DE DATOS: GORM
Genero 1 * Película
![Page 36: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/36.jpg)
SERVICIOS
![Page 37: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/37.jpg)
SERVICIOS
![Page 38: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/38.jpg)
SERVICIOS
![Page 39: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/39.jpg)
SERVICIOS
![Page 40: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/40.jpg)
SERVICIOS
![Page 41: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/41.jpg)
SERVICIOS
![Page 42: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/42.jpg)
SERVICIOS
singleton prototype request session
![Page 43: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/43.jpg)
CONTROLLER TESTS
• a
![Page 44: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/44.jpg)
CONTROLLER TESTS
• a
![Page 45: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/45.jpg)
CONTROLLER TESTS
• a
![Page 46: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/46.jpg)
CONTROLLER TESTS: SPOCK
• a
![Page 47: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/47.jpg)
GORM: TESTING
• grails-datastore-gorm-tck • In-memory GORM implementation
![Page 48: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/48.jpg)
• constraints
![Page 49: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/49.jpg)
TEST DE INTEGRACIÓN
• Arranca instancia de Grails
• Base de datos en memoria
• Environment “test”
• Cada test en una transacción
![Page 50: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/50.jpg)
TEST INTEGRACIÓN: CONFIG
![Page 51: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/51.jpg)
TEST INTEGRACIÓN: BOOTSTRAP
![Page 52: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/52.jpg)
TEST INTEGRACIÓN: BOOTSTRAP
![Page 53: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/53.jpg)
Y MUCHO MAS: SPOCK
• a
![Page 54: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/54.jpg)
Y MUCHO MÁS: TEST FUNCIONALES
• a
![Page 55: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/55.jpg)
¿TE GUSTA GROOVY?
En Madrid, 4 de Nov. de 2011
• Apúntate en http://greach.es
![Page 56: Introducción al testing con Grails (XPWeek)](https://reader034.vdocuments.net/reader034/viewer/2022052411/5578ec41d8b42a5c5c8b4db9/html5/thumbnails/56.jpg)
¡GRACIAS!
¿Preguntas? ¿Dudas?