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

Quick Search    Search Deep

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


1   package junit.extensions.abbot;
2   
3   import junit.framework.*;
4   import abbot.*;
5   import abbot.script.*;
6   import java.awt.*;
7   import java.awt.event.ActionListener;
8   import java.util.*;
9   import javax.swing.filechooser.FileFilter;
10  
11  import java.io.File;
12  import junit.framework.Test;
13  import junit.framework.TestCase;
14  import junit.framework.TestSuite;
15  import junit.textui.TestRunner;
16  
17  /** Simple wrapper for a test script to run under JUnit. */
18  
19  public class ScriptFixture extends TestCase {
20  
21      private static final ComponentFinder finder = 
22          DefaultComponentFinder.getFinder();
23      private Script script;
24  
25      /** Construct a test case with the given name.  It is essential that the
26       * name be passed to super() unmodified, or the JUnit GUI will consider it
27       * a different test.
28       */
29      public ScriptFixture(String filename) { 
30          super(filename);
31          script = new Script(filename);
32      }
33  
34      /** Obtain a component finder to look up components. */
35      protected ComponentFinder getFinder() {
36          return finder;
37      }
38  
39      /** Override the default TestCase runTest method to invoke the script. */
40      protected void runTest() throws Throwable {
41          Log.log("Running " + script + " with " + getClass());
42          StepRunner runner = new StepRunner();
43          try {
44              runner.run(script);
45          }
46          finally {
47              // Don't let this test's components interfere with subsequent tests
48              runner.terminate();
49              Log.log(script.toString() + " finished");
50          }
51      }
52  
53      /** Assumes each argument is an Abbot script.  Runs each one. */
54      public static void main(String[] args) {
55          ScriptTestSuite.main(args);
56      }
57  }