Created
April 21, 2013 23:55
-
-
Save delucas/5431625 to your computer and use it in GitHub Desktop.
UNTreF - Ejemplo de Pruebas: Clase Nota
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ar.edu.untref.pruebas; | |
public class Nota { | |
private int nota; | |
public Nota(int nota) { | |
if (nota >=0 && nota <=10) { | |
this.nota = nota; | |
} else { | |
Error notaNoValida = new Error("La nota no es válida"); | |
throw notaNoValida; | |
} | |
} | |
public int getNota() { | |
return this.nota; | |
} | |
public boolean aprobado() { | |
return this.nota >= 4; | |
} | |
public boolean desaprobado() { | |
return this.nota < 4; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package ar.edu.untref.pruebas; | |
import org.junit.Assert; | |
import org.junit.Test; | |
public class NotaTests { | |
@Test public void testQueNotaDesaprobadaNoEsAprobado() { | |
// preparación | |
Nota miNota = new Nota(3); | |
// ejecución | |
boolean resultado = miNota.aprobado(); | |
// contrastación | |
Assert.assertFalse("un 3 no debe ser aprobado", resultado); | |
} | |
@Test public void testQueNotaAprobadaEsAprobado() { | |
// preparación | |
Nota miNota = new Nota(7); | |
// ejecución | |
boolean resultado = miNota.aprobado(); | |
// contrastación | |
Assert.assertTrue("un 7 debe ser aprobado", resultado); | |
} | |
// contrastacion | |
@Test(expected=Error.class) | |
public void testMazinger() { | |
// preparacion / ejecucion | |
new Nota(-1); | |
} | |
@Test public void testGetNota() { | |
Nota miNota = new Nota(3); | |
int resultado = miNota.getNota(); | |
Assert.assertEquals("Una nota instanciada con 3 vale 3", 3, resultado); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment