Donnerstag, 14. Januar 2010

The Art of Unit Testing - El Arte del Unit Testing

[Spanish, scroll down for the english version.]
El Arte de Unit Testing.

Hace ya muchos años, cuando aun estaba en los ultimos años de colegio, mi entonces Profesor de Matematica hizo el siguiente comentario cuando nos estaba enseñando calculo:

"Cualquiera puede derivar (functiones). En cambio, integrar es un arte."

En forma similar, el libro "The Art of Unit Testing" de Roy Osherove es la pura verdad, es un arte. En terminos simples, Unit Testing quiere decir asegurarse que el codigo que hemos escrito cumple con los requerimientos que salen de las fases de analisis y diseño de un programa. Pero es mucho mas que eso. Como el autor lo dice, todos hemos realizado algun tipo de pruebas sobre nuestro codigo para asegurarnos que nuestros programas corren como deberian, pero muy pocos hacen Unit Testing.

Unit Testing es una filosofia de desarrollo de Software, una religion. Y la unica y verdadera iglesia es la Iglesia del TDD (Test Driven Development: Desarrollo Impulsado por Tests). Y el primer mandamiento de la iglesia del TDD es el siguiente:
1. No teclearas ni una sola linea de codigo en tu aplicacion, si no has definido un test que falle para comprobar su funcionalidad antes.

Dejemos la religion de lado. Mientras me adentro en el mundo de TDD y Unit Tests, mi objetivo es quedarme con lo que me parece logico y practico. No me quedan dudas que el TDD es una filosofia de desarrollo de software que, si se implementa en forma consecuente, definitivamente mejorara la calidad del codigo escrito.

De momento los dejo con la recomendacion del libro de Osherove [http://www.amazon.com/Art-Unit-Testing-Examples-Net/dp/1933988274/], y para el programador the C# que quiera poner manos en la masa, vea aqui: [http://www.nunit.org/index.php]

Es lamentable que libros como este tarden años en ser traducidos al español.

[English]

The Art of Unit Testing

Long time ago while I was still in school, my mathematics professor made the following comment about Calculus:

"Anyone can derive (functions). However, integrating is an Art"

Similarly, the book "The Art of Unit Testing" by Roy Osherove could not have put it better, Unit Testing is an art. Im simple terms, Unit Testing means making sure that the code we write complies with the requirements that come out of the Analysis and Design phases in Application Development. And yet it is much more than that. As the author notes, we have all done some kind of testing on our code to make sure our programs run as they should, but only few do real Unit Testing.

Unit Testing is a Software Development philosophy, a religion. And it's one and true church is the church of TDD (Test Driven Development). And the first commandment of TDD is the following:
1. Thou shalt not write a single aplication line of code, unless you have written a failing test of the functionality beforehand.

I'm leaving religion aside. As i begin my journey in the world of TDD and Unit Tests, my focus is to keep what i consider logical and practical. I have no doubt that TDD is a software development philosophy that, when applied consequently, will definitely improve the quality of the code written.

For the moment, I leave you with the recommended reading of Osherove's book [http://www.amazon.com/Art-Unit-Testing-Examples-Net/dp/1933988274/], and for the C# programmer that want to get down to business, this is a good starting place: [http://www.nunit.org/index.php]