Bueno para esta publicación me toca presentar las pruebas unitarias que implemente para mi proyecto las cuales son las siguientes :
Prueba Writer
Para realizar esta prueba utilice un archivo de texto llamado "ejemplo.txt" con este archivo en el método prueba cree dos objetos de este a partir del archivo, uno de los objetos lo sobrescribí con el contenido del archivo "ejemplo.txt" y el otro lo deje igual. Al comparar me dirían si el contenido del archivo se recuperaba exitosamente o si la clase tenia errores.
Este es el código de la prueba:
package pruebas; import java.io.*; import java.lang.StringBuffer; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import junit.textui.TestRunner; public class PruebaWriter extends TestCase { protected Writer w; private File prueba; private File secundario; private StringBuffer buffer = new StringBuffer(); protected void setUp() { try{ this.prueba = new File("ejemplo.txt"); this.secundario = new File("ejemplo.txt"); this.w = new Writer("",secundario,buffer); }catch(Exception e){ e.printStackTrace(); } return; } public static Test suite() { return new TestSuite(PruebaWriter.class); } public void testEscribiendo() { System.out.println("Escribiendo Documento..."); buffer.append("Su hermano fue en su busca, a tierras muy lejanas."); w.escribirDocumento(); w.cerrarArchivo(); super.assertEquals(secundario,prueba); return; } public static void main(String[] args) { TestRunner.run(PruebaWriter.suite()); return; } }
Prueba Reader
Para comprobar el correcto funcionamiento de esta clase utilice un archivo de prueba llamado "ejemplo.txt" leyendo el contenido por medio de la clase Reader y después pasándolo a un String me fue mas fácil comparar ese String con otro que yo hice donde estaba el contenido que yo había puesto en archivo,
package pruebas; import java.io.*; import java.lang.StringBuffer; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; import junit.textui.TestRunner; public class PruebaReader extends TestCase { protected Reader r; private File prueba; private StringBuffer buffer = new StringBuffer(); protected void setUp() { try{ this.prueba = new File("ejemplo.txt"); this.r = new Reader("",prueba,buffer); }catch(Exception e){ e.printStackTrace(); } return; } public static Test suite() { return new TestSuite(PruebaReader.class); } public void testLeyendo() { System.out.println("Devolviendo Documento..."); r.devolverDocumento(); r.cerrarArchivo(); super.assertEquals("Su hermano fue en su busca, a tierras muy lejanas.",buffer.toString()); return; } public static void main(String[] args) { TestRunner.run(PruebaReader.suite()); return; } }
Prueba