Top Banner
TESTING Y TDD CON GROOVY Y GRAILS por Alberto Vilches http://albertovilches.com Twitter: @albertovilches
56

Introducción al testing con Grails (XPWeek)

Jun 11, 2015

Download

Technology

Alberto Vilches

Charla para la XPWeek el 23 de Septiembre de 2011
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Introducción al testing con Grails (XPWeek)

TESTING Y TDD CON GROOVY Y GRAILS

por Alberto Vilches http://albertovilches.com

Twitter: @albertovilches

Page 2: Introducción al testing con Grails (XPWeek)

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)

AGENDA

•  Introducción a Groovy •  Testing con Groovy

•  Introducción a Grails •  Testing con Grails

Page 4: Introducción al testing con Grails (XPWeek)

¿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)

¿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)

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)

GROOVY POWER ASSERTS

Page 8: Introducción al testing con Grails (XPWeek)

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)

MOCKING CON GROOVY

Closure as OnlyMethodInterface

Page 10: Introducción al testing con Grails (XPWeek)

MOCKING CON GROOVY

Map as Interface

Page 11: Introducción al testing con Grails (XPWeek)

MOCKING CON GROOVY

Expando

Page 12: Introducción al testing con Grails (XPWeek)

MOCKING CON GROOVY

a

Page 13: Introducción al testing con Grails (XPWeek)

MOCKING CON GROOVY

a

Page 14: Introducción al testing con Grails (XPWeek)

MOCKING CON GROOVY

a

Page 15: Introducción al testing con Grails (XPWeek)

MOCKING CON GROOVY

a

Page 16: Introducción al testing con Grails (XPWeek)

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)

¿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)

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)

ESTRUCTURA DEL PROYECTO

Page 20: Introducción al testing con Grails (XPWeek)

VISIÓN GENERAL

CONTROLADORES

Uso directo

Inyección Spring

Page 21: Introducción al testing con Grails (XPWeek)

VISIÓN GENERAL

CONTROLADORES

VISTAS

Uso directo

Inyección Spring

Page 22: Introducción al testing con Grails (XPWeek)

VISIÓN GENERAL

CONTROLADORES

VISTAS

TAGLIBS

Uso directo

Inyección Spring

Page 23: Introducción al testing con Grails (XPWeek)

VISIÓN GENERAL

CONTROLADORES

SERVICIOS

VISTAS

TAGLIBS

Uso directo

Inyección Spring

Page 24: Introducción al testing con Grails (XPWeek)

VISIÓN GENERAL

CONTROLADORES

SERVICIOS

VISTAS

TAGLIBS

Uso directo

Inyección Spring

Page 25: Introducción al testing con Grails (XPWeek)

VISIÓN GENERAL

CONTROLADORES

SERVICIOS

VISTAS

CLASES DE DOMINIO

TAGLIBS

Uso directo

Inyección Spring

Page 26: Introducción al testing con Grails (XPWeek)

VISIÓN GENERAL

CONTROLADORES

SERVICIOS

VISTAS

CLASES DE DOMINIO

TAGLIBS

Uso directo

Inyección Spring

Page 27: Introducción al testing con Grails (XPWeek)

MVC: CONTROLADORES

Page 28: Introducción al testing con Grails (XPWeek)

MVC: CONTROLADORES

Page 29: Introducción al testing con Grails (XPWeek)

MVC: CONTROLADORES

Page 30: Introducción al testing con Grails (XPWeek)

MVC: CONTROLADORES

params session request response …

Page 31: Introducción al testing con Grails (XPWeek)

MODELO DE DATOS: GORM

Page 32: Introducción al testing con Grails (XPWeek)

MODELO DE DATOS: GORM

Page 33: Introducción al testing con Grails (XPWeek)

MODELO DE DATOS: GORM

Page 34: Introducción al testing con Grails (XPWeek)

MODELO DE DATOS: GORM

Page 35: Introducción al testing con Grails (XPWeek)

MODELO DE DATOS: GORM

Genero 1 * Película

Page 36: Introducción al testing con Grails (XPWeek)

SERVICIOS

Page 37: Introducción al testing con Grails (XPWeek)

SERVICIOS

Page 38: Introducción al testing con Grails (XPWeek)

SERVICIOS

Page 39: Introducción al testing con Grails (XPWeek)

SERVICIOS

Page 40: Introducción al testing con Grails (XPWeek)

SERVICIOS

Page 41: Introducción al testing con Grails (XPWeek)

SERVICIOS

Page 42: Introducción al testing con Grails (XPWeek)

SERVICIOS

singleton prototype request session

Page 43: Introducción al testing con Grails (XPWeek)

CONTROLLER TESTS

•  a

Page 44: Introducción al testing con Grails (XPWeek)

CONTROLLER TESTS

•  a

Page 45: Introducción al testing con Grails (XPWeek)

CONTROLLER TESTS

•  a

Page 46: Introducción al testing con Grails (XPWeek)

CONTROLLER TESTS: SPOCK

•  a

Page 47: Introducción al testing con Grails (XPWeek)

GORM: TESTING

•  grails-datastore-gorm-tck •  In-memory GORM implementation

Page 48: Introducción al testing con Grails (XPWeek)

•  constraints

Page 49: Introducción al testing con Grails (XPWeek)

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)

TEST INTEGRACIÓN: CONFIG

Page 51: Introducción al testing con Grails (XPWeek)

TEST INTEGRACIÓN: BOOTSTRAP

Page 52: Introducción al testing con Grails (XPWeek)

TEST INTEGRACIÓN: BOOTSTRAP

Page 53: Introducción al testing con Grails (XPWeek)

Y MUCHO MAS: SPOCK

•  a

Page 54: Introducción al testing con Grails (XPWeek)

Y MUCHO MÁS: TEST FUNCIONALES

•  a

Page 55: Introducción al testing con Grails (XPWeek)

¿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)

¡GRACIAS!

¿Preguntas? ¿Dudas?