| Home >> All >> junit >> extensions >> [ abbot Javadoc ] |
Source code: junit/extensions/abbot/RepeatHelper.java
1 package junit.extensions.abbot; 2 3 import abbot.Log; 4 import junit.framework.*; 5 import junit.extensions.RepeatedTest; 6 7 /** Convenience functions to wrap a given test case such that individual 8 methods may be run with heavy repetition, and default suites run with 9 light repetition. 10 */ 11 12 public class RepeatHelper { 13 14 // no instantiations 15 private RepeatHelper() { } 16 17 public static void runTests(String[] args, Class testClass) { 18 args = Log.init(args); 19 try { 20 Test test; 21 if (args.length > 0 && args[0].startsWith("test")) { 22 test = (Test)testClass.getConstructor(new Class[]{ 23 String.class 24 }).newInstance(new Object[] { args[0] }); 25 // Really stress-test individual cases 26 int repeat = 1; 27 if (args.length > 1) { 28 try { repeat = Integer.parseInt(args[1]); } 29 catch(NumberFormatException nfe) { } 30 } 31 test = new RepeatedTest(test, repeat); 32 } 33 else { 34 int repeat = 1; 35 if (args.length == 1) { 36 try { repeat = Integer.parseInt(args[0]); } 37 catch(NumberFormatException nfe) { } 38 } 39 try { 40 test = (Test)testClass.getMethod("suite", null). 41 invoke(null, null); 42 } 43 catch(Exception exc) { 44 test = new TestSuite(testClass); 45 } 46 if (args.length > 0) { 47 try { repeat = Integer.parseInt(args[0]); } 48 catch(NumberFormatException nfe) { } 49 } 50 // Mildly stress-test the whole group 51 test = new RepeatedTest(test, repeat); 52 } 53 junit.textui.TestRunner runner = new junit.textui.TestRunner(); 54 try { 55 TestResult r = runner.doRun(test, false); 56 if (!r.wasSuccessful()) 57 System.exit(-1); 58 System.exit(0); 59 } 60 catch(Throwable thr) { 61 System.err.println(thr.getMessage()); 62 System.exit(-2); 63 } 64 } 65 catch(Exception exc) { 66 System.err.println(exc.getMessage()); 67 System.exit(-2); 68 } 69 } 70 }