the art of unit testing

14
Unit Test El arte de test unitario

Upload: rafael-avaria

Post on 25-May-2015

198 views

Category:

Technology


1 download

DESCRIPTION

unit test, basic principles

TRANSCRIPT

Page 1: The art of unit testing

Unit TestEl arte de test unitario

Page 2: The art of unit testing

Definición

Es un código que invoca a otro código, Usualmente un método.

Chequea si una presunción es correcta.

Se dice unitario pues prueba una sola funcionalidad.

………………………….¿?

Page 3: The art of unit testing

Propiedades del Test unitario

Debe ser automatizado y repetitivo.

DEBE SER FACIL DE IMPLEMENTAR

Una vez escrito debe permanecer para futuros usos

Cualquiera los puede ejecutar, idealmente oprimiendo un botón.

Debe correr rápido.

Page 4: The art of unit testing

Un test simple

Page 5: The art of unit testing

La Class Assert

Page 6: The art of unit testing

Del Ejemplo Anterior

El nombre del test es importante

DataEntregada_NombreMetodo_Resultado

Nos ayuda a buscarlo rápido

En un proyecto se escribe varios test por funcionalidad

Page 7: The art of unit testing

Muy Bonito, pero……

En mi proyecto tengo que integrar Servicios Web.

Hay varios hilos.

……………..

Como funciona el test unitario

Examinemos de cerca un requerimiento real.

Page 8: The art of unit testing

Stubs and Mocks

FAKE SERVICIO WEB

Page 9: The art of unit testing

STUBS V/S MOCK

STUB debe satisfacer dependenciasSi nuestro funcionalidad bajo test depende de esta

clase, se habla de stub y se deben cumplir ciertas reglas. Se espera un valor Los argumentos deben tener cierto formato

Si no se cumplen estas Condiciones, nuestra funcionalidad bajo test no se comporta adecuadamente

MOCK es una clase tonta Si nuesta funcionalidad bajo test no depende de esta

clase pera la necesita.

Page 10: The art of unit testing

Por que usar Mock o Stub

Por que solo se debe testear nuestra logica

Bajo la premisa del Test unitario no tiene sentido probar un servicio web. Que ni siquiera esta escrito por nosotros o del que no tenemos control.

Que sentido tiene probar cosas ultraprovadas y que forman parte de la suite de MSVS, PHP, Ruby…… no vas a descubrir fallas.

Page 11: The art of unit testing

ALGUNOS EJEMPLOS

Page 12: The art of unit testing

Rhino Mock

Page 13: The art of unit testing

Rhino Mock - Continua

Page 14: The art of unit testing

Mas de Rhino Mock