sis.util.IOUtilTest


 package sis.util; import junit.framework.*; import java.io.*; public class IOUtilTest extends TestCase {    static final String FILENAME1 = "IOUtilTest1.txt";    static final String FILENAME2 = "IOUtilTest2.txt";    public void testDeleteSingleFile() throws IOException {       create(FILENAME1);       assertTrue(IOUtil.delete(FILENAME1));       TestUtil.assertGone(FILENAME1);    }    public void testDeleteMultipleFiles() throws IOException {       create(FILENAME1, FILENAME2);       assertTrue(IOUtil.delete(FILENAME1, FILENAME2));       TestUtil.assertGone(FILENAME1, FILENAME2);    }    public void testDeleteNoFile() throws IOException {       TestUtil.delete(FILENAME1);       assertFalse(IOUtil.delete(FILENAME1));    }    public void testDeletePartiallySuccessful() throws IOException {       create(FILENAME1);       TestUtil.delete(FILENAME2);       assertFalse(IOUtil.delete(FILENAME1, FILENAME2));       TestUtil.assertGone(FILENAME1);    }    private void create(String... filenames) throws IOException {       for (String filename: filenames) {          TestUtil.delete(filename);          new File(filename).createNewFile();       }    } } 

The most interesting aspect of IOUtilTest is that it contains four test methods, each testing the same IOUtil method delete. Each test proves a typical scenario. There are probably many more tests possible. It's up to you to decide whether you have enough tests to give you the confidence you need in your code.

Err in the direction of too many tests instead of too few.




Agile Java. Crafting Code with Test-Driven Development
Agile Javaв„ў: Crafting Code with Test-Driven Development
ISBN: 0131482394
EAN: 2147483647
Year: 2003
Pages: 391
Authors: Jeff Langr

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net