16.05.2013 Views

de Dattatec.com SRL. - Pixels & Code

de Dattatec.com SRL. - Pixels & Code

de Dattatec.com SRL. - Pixels & Code

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Nuestra aplicación a probar será<br />

ampliada; modificaremos la única<br />

Activity para que sea una simple<br />

calculadora. Ingreso dos valores, y al<br />

hacer clic en ‹Multiplicar› se mostrará<br />

el resultado <strong>de</strong> multiplicarlos entre sí.<br />

Por simplicidad se <strong>de</strong>ja este ejercicio<br />

para el lector, y queda disponible<br />

el proyecto en el siguiente link:<br />

http://pixelsco<strong>de</strong>.<strong>com</strong>/downloads/<br />

HelloPixelAndCo<strong>de</strong>_Calculadora.zip.<br />

Así que ahora, vamos a probar esta<br />

mini-calculadora.<br />

Para usar Robotium en un proyecto <strong>de</strong><br />

testing, realizamos estos pasos:<br />

• Descargar el archivo robotiumsolo-3-1.jar<br />

que contiene el<br />

framework <strong>de</strong>s<strong>de</strong>: http://co<strong>de</strong>.google.<br />

<strong>com</strong>/p/robotium/<br />

Será necesario que tengamos un<br />

proyecto Android con la aplicación que<br />

<strong>de</strong>seamos testear, y <strong>com</strong>o en nuestro<br />

caso, ya creado un proyecto <strong>de</strong> Test<br />

Android (si no, crearlo <strong>com</strong>o vimos<br />

anteriormente: File->New->Project-<br />

>Android->Android Test Project).<br />

• Necesitamos una referencia a<br />

Robotium <strong>de</strong>s<strong>de</strong> nuestro proyecto.<br />

Para eso, vamos a agregar el archivo<br />

jar: clic <strong>de</strong>recho en el proyecto-<br />

>Build path->Configure Build Path<br />

y en Properties, clic en la pestaña<br />

Libraries, para agregar el jar <strong>de</strong><br />

Robotium, <strong>com</strong>o se muestra en la<br />

siguiente imagen:<br />

• Dentro <strong>de</strong> nuestro proyecto <strong>de</strong> test,<br />

creamos una nueva clase con un test<br />

<strong>de</strong> ejemplo: New->Class, <strong>de</strong>rivamos<br />

esta clase <strong>de</strong> ActivityInstrumentatio<br />

nTestCase2 , <strong>com</strong>o se muestra en la<br />

captura <strong>de</strong> pantalla:<br />

• Abrimos el archivo<br />

MiPrimerTestAutomatico.java y<br />

veremos este código:<br />

package <strong>com</strong>.msalvetti.<br />

pixelandco<strong>de</strong>.helloworld.test;<br />

import android.test.<br />

ActivityInstrumentationTestCase2;<br />

public class MiPrimerTestAutomtico<br />

extends ActivityInstrumentationTestC<br />

35

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!