Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: junit/extensions/abbot/ScriptTestSuiteTest.java


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