01: package junit.extensions.abbot;
02:
03: import java.io.File;
04: import java.util.*;
05:
06: import junit.framework.*;
07:
08: /**
09: * Verify we can extend a ScriptTestSuite.
10: */
11: public class ScriptTestSuiteTest extends TestCase {
12:
13: private static int runs;
14:
15: public static class MyScriptFixture extends ScriptFixture {
16: public MyScriptFixture(String filename) {
17: super (filename);
18: }
19:
20: protected void runTest() throws Throwable {
21: ++runs;
22: }
23: }
24:
25: /** Ensure that a suite generated with a derived class actually
26: instantiates those classes.
27: */
28: public void testDerivedClass() throws Throwable {
29: runs = 0;
30: Test suite = new ScriptTestSuite(MyScriptFixture.class,
31: "src/example");
32: suite.run(new TestResult());
33: assertTrue("Derived test fixture class was never run",
34: runs != 0);
35: }
36:
37: /** Create a few temp files, the test suite should pick them up. */
38: public void testGenerateFilenames() throws Throwable {
39: File tmp = File.createTempFile(getName(), "-dummy");
40: File tmpdir = tmp.getParentFile();
41: tmp.delete();
42: File[] files = tmpdir.listFiles();
43: for (int i = 0; i < files.length; i++) {
44: if (files[i].getName().startsWith(getName())
45: && files[i].getName().endsWith(".tst")) {
46: files[i].delete();
47: }
48: }
49:
50: File f1 = File.createTempFile(getName(), ".tst");
51: f1.deleteOnExit();
52: File f2 = File.createTempFile(getName(), ".tst");
53: f2.deleteOnExit();
54: File f3 = File.createTempFile(getName(), ".tst");
55: f3.deleteOnExit();
56:
57: String[] flist = ScriptTestSuite.findFilenames(f1
58: .getParentFile().getAbsolutePath(), false);
59: List list = new ArrayList();
60: for (int i = 0; i < flist.length; i++) {
61: String fn = flist[i];
62: if (fn.indexOf(getName()) != -1 && fn.endsWith(".tst")) {
63: list.add(fn);
64: }
65: }
66: assertEquals("Wrong number of files", 3, list.size());
67: assertTrue("Missing f1", list.contains(f1.getAbsolutePath()));
68: assertTrue("Missing f2", list.contains(f2.getAbsolutePath()));
69: assertTrue("Missing f3", list.contains(f3.getAbsolutePath()));
70: }
71:
72: public ScriptTestSuiteTest(String name) {
73: super (name);
74: }
75:
76: public static void main(String[] args) {
77: TestHelper.runTests(args, ScriptTestSuiteTest.class);
78: }
79: }
|