View Javadoc
1   
2   package eu.simuline.testhelpers;
3   
4   import eu.simuline.util.Finder;
5   
6   import java.io.File;
7   
8   /**
9    * Runs a bunch of tests using {@link Actions#runTestClass(String)}. 
10   *
11   * @author <a href="mailto:ernst.reissner@simuline.eu">Ernst Reissner</a>
12   * @version 1.0
13   */
14  public abstract class JUnitSingleTester {
15  
16      /**
17       * Runs all testclasses in the directory given by the 0th argument 
18       * in the package given by the 1st argument. 
19       * The package separator is the file separator. 
20       *
21       * @param args
22       *    two arguments together consituting the path to the classes: 
23       *    The 0th one the path to the java classes, 
24       *    the 1st one the package to be run 
25       *    with file separator as package separator. 
26       */
27      @SuppressWarnings("checkstyle:nowhitespacebefore")
28      public static void main(String[] args) { //throws ClassNotFoundException {
29  	if (args.length != 2) {
30  	    throw new IllegalArgumentException
31  		("Expected exactly two araguments but found " + 
32  		 args.length + ". ");
33  	}
34  
35  	File baseDir = new File(args[0] + args[1]);
36  	String dirName = baseDir.getAbsolutePath();
37  	Finder finder = Finder.path(baseDir)
38  //	    .name(".*arithmetics.*")
39  	    .not(Finder.nameFilter(".*arithmetics.*"))
40  	    .not(Finder.nameFilter(".*graphDV.*"))
41  //	    .name(".*class")
42  	    .name(".*Test\\.class")
43  //	    .print(System.out)
44  	    ;
45  
46  	File clsFile;
47  	String clsName;
48  
49  	while (finder.hasNext()) {
50  	    clsFile = finder.next();
51  	    clsName = clsFile.getAbsolutePath();
52  System.out.println("clsName" + clsName);
53  
54  	    assert clsName.startsWith(dirName);
55  	    clsName = clsName.substring(args[0].length());
56  	    clsName = clsName.substring(0,
57  					clsName.length() - ".class".length());
58  System.out.println("clsName" + clsName);
59  
60  	    clsName = clsName.replace(System.getProperty("file.separator")
61  				      .charAt(0), '.');
62  	    System.out.println("clsName: " + clsName);
63  	    Actions.runTestClass(clsName);
64  	} // while 
65  
66      }
67  } // class JUnitSingleTester 
68