Edit: No JUnit 4 disponible en este momento.JUnit Exception Testing
Hola,
Tengo una pregunta acerca de las pruebas excepción "inteligente" con JUnit. En este momento, lo hago de esta manera:
public void testGet() {
SoundFileManager sfm = new SoundFileManager();
// Test adding a sound file and then getting it by id and name.
try {
SoundFile addedFile = sfm.addSoundfile("E:\\Eclipse_Prj\\pSound\\data\\Adrenaline01.wav");
SoundFile sf = sfm.getSoundfile(addedFile.getID());
assertTrue(sf!=null);
System.out.println(sf.toString());
sf = sfm.getSoundfileByName("E:\\Eclipse_Prj\\pSound\\data\\Adrenaline01.wav");
assertTrue(sf!=null);
System.out.println(sf.toString());
} catch (RapsManagerException e) {
System.out.println(e.getMessage());
}
// Test get with invalid id.
try {
sfm.getSoundfile(-100);
fail("Should have raised a RapsManagerException");
} catch (RapsManagerException e) {
System.out.println(e.getMessage());
}
// Test get by name with invalid name
try {
sfm.getSoundfileByName(new String());
fail("Should have raised a RapsManagerException");
} catch (RapsManagerException e) {
System.out.println(e.getMessage());
}
}
Como se puede ver, necesito bloque/captura de un intento para cada función que se supone que es una excepción. Parece que no es una buena forma de hacerlo, ¿o no hay posibilidad de reducir el uso de try/catch?
Yo sugeriría en contra de hacer System.out.println dentro prueba. System.out y System.err tienden a mezclar y producir salida de prueba confusa. – RockyMM