|
|
| (No se muestran 3 ediciones intermedias de otro usuario) |
| Línea 1: |
Línea 1: |
| − | "Tests with Parameters" le permite simplemente agregar parámetros a los métodos de prueba [[JUnit]]. Twip llama a los métodos con todas las combinaciones posibles de sus parámetros... o por lo menos un subconjunto razonable de los valores comunes en el caso de los Integers, Strings, etc. Se puede definir un conjunto de valores propios para su uso y/o se puede reducir los valores fijados con la anotación "Assume", por ejemplo, @Assume("> = 0"). Los valores por defecto existen para los tipos primitivos (int, etc), sus wrappers de clase (Integer, etc), enum y Strings. Para otros tipos o para un conjunto de valores diferentes, se puede definir un método estático o un atributo y anotar los parámetros de su método de prueba, o puede anotar en el campo o método para inyectar los valores por tipo.
| + | Ya learn something new eveyardy. It's true I guess! |
| − | | |
| − | == Requerimientos<br> ==
| |
| − | | |
| − | TwiP requiere JUnit 4.5 and Java 1.5.
| |
| − | | |
| − | == Test de tipos primitivos ==
| |
| − | | |
| − | <code java5>
| |
| − | import net.sf.twip.Assume;
| |
| − | import net.sf.twip.TwiP;
| |
| − | import org.junit.Test;
| |
| − | import org.junit.runner.RunWith;
| |
| − | | |
| − | | |
| − | @RunWith(TwiP.class)
| |
| − | public class tiposTest {
| |
| − | | |
| − | @Test
| |
| − | public void intTest(int numero) {
| |
| − | System.out.println(numero);
| |
| − | }
| |
| − | | |
| − | @Test
| |
| − | public void integerTest(Integer numero) {
| |
| − | System.out.println(numero);
| |
| − | }
| |
| − | | |
| − | @Test
| |
| − | public void doubleTest(Double numero) {
| |
| − | System.out.println(numero);
| |
| − | }
| |
| − | | |
| − | @Test
| |
| − | public void stringTest(@Assume("=null") String string) {
| |
| − | System.out.println("| " + string + " |");
| |
| − | }
| |
| − | | |
| − | @Test
| |
| − | public void booleanTest(boolean flag1) {
| |
| − | System.out.println(flag1);
| |
| − | }
| |
| − | | |
| − | }
| |
| − | </code>
| |
| − | | |
| − | == Test de entidad propia<br> ==
| |
| − | | |
| − | <code>
| |
| − | public class Persona {
| |
| − | | |
| − | int id;
| |
| − | | |
| − | String nombre;
| |
| − | | |
| − | public String getApellido() {
| |
| − | return apellido;
| |
| − | }
| |
| − | | |
| − | public void setApellido(String apellido) {
| |
| − | this.apellido = apellido;
| |
| − | }
| |
| − | | |
| − | String apellido;
| |
| − | | |
| − | public Persona(int id, String nombre, String apellido) {
| |
| − | this.id = id;
| |
| − | this.nombre = nombre;
| |
| − | this.apellido = apellido;
| |
| − | }
| |
| − | | |
| − | | |
| − | public Persona(int id, String nombre) {
| |
| − | this.id = id;
| |
| − | this.nombre = nombre;
| |
| − | }
| |
| − | | |
| − | | |
| − | public int getId() {
| |
| − | return id;
| |
| − | }
| |
| − | | |
| − | public void setId(int id) {
| |
| − | this.id = id;
| |
| − | }
| |
| − | | |
| − | public String getNombre() {
| |
| − | return nombre;
| |
| − | }
| |
| − | | |
| − | public void setNombre(String nombre) {
| |
| − | this.nombre = nombre;
| |
| − | }
| |
| − | | |
| − | public String toString() {
| |
| − | return id+" - "+nombre;
| |
| − | }
| |
| − | | |
| − | }
| |
| − | </code>
| |
| − | | |
| − | <code>
| |
| − | import net.sf.twip.Assume;
| |
| − | import net.sf.twip.AutoTwip;
| |
| − | import net.sf.twip.TwiP;
| |
| − | import net.sf.twip.Values;
| |
| − | import org.junit.Test;
| |
| − | import org.junit.runner.RunWith;
| |
| − | | |
| − | | |
| − | @RunWith(TwiP.class)
| |
| − | public class PersonaTest {
| |
| − | | |
| − | public static final Persona[] PERSONAS = {new Persona(1, "nombre1"), new Persona(2, "nombre2")};
| |
| − | | |
| − | @AutoTwip
| |
| − | public static Persona persona(int id, String nombre, String apellido) {
| |
| − | return new Persona(id, nombre, apellido);
| |
| − | }
| |
| − | | |
| − | @Test
| |
| − | public void personasTest(@Values("PERSONAS") Persona persona) {
| |
| − | System.out.println(persona.toString());
| |
| − | }
| |
| − | | |
| − | @Test
| |
| − | public void personaTest(@Assume("=null") Persona persona) {
| |
| − | | |
| − | if (persona != null) {
| |
| − | System.out.println(persona.toString());
| |
| − | } else {
| |
| − | System.out.println("Control null");
| |
| − | }
| |
| − | }
| |
| − | }
| |
| − | </code>
| |
| − | | |
| − | == Ver también ==
| |
| − | | |
| − | *[http://twip.sourceforge.net/ TwiP - Tests with Parameters]
| |
Ya learn something new eveyardy. It's true I guess!