1 package jester; 2 3 import java.io.*; 4 5 45 46 public class TestTester { 47 public static final String VERSION = "1.37"; 48 49 public static final String TIMEOUT_FILENAME = "jesterTimeout.txt"; 50 51 private TestRunner testRunner; 52 private ClassIterator classIterator; 53 private ClassTestTester classTestTester; 54 private static MainArguments mainArguments; 55 56 public TestTester(TestRunner testRunner, ClassIterator classIterator, ClassTestTester classTestTester) { 57 super(); 58 this.testRunner = testRunner; 59 this.classIterator = classIterator; 60 this.classTestTester = classTestTester; 61 } 62 63 public static void main(String args[]) { 64 try { 65 try { 66 mainArguments = new MainArguments(args, new FileExistenceChecker(){ 67 public boolean exists(String fileName) { 68 return new File(fileName).exists(); 69 } 70 }); 71 } 72 catch (JesterArgumentException e) { 73 System.out.println(e); 74 System.out.println(); 75 MainArguments.printUsage(System.out, VERSION); 76 System.exit(0); 77 } 78 System.out.println("Use classpath: " + System.getProperty(MainArguments.CLASSPATH_PROPERTY)); 79 80 deleteTimeoutFile(); 81 82 long runTime = doMain(); 83 System.out.println("took " + (runTime / (1000 * 60)) + " minutes"); 84 } 85 catch (Exception e) { 86 e.printStackTrace(); 87 } 88 } 89 90 private static long doMain() throws IOException, SourceChangeException { 91 long t1 = System.currentTimeMillis(); 92 Configuration configuration = new RealConfiguration(RealConfiguration.DEFAULT_CONFIGURATION_FILENAME); 93 Report aReport = null; 94 FileWriter reportFileWriter = new FileWriter(configuration.xmlReportFileName()); 95 XMLReportWriter anXMLReportWriter = new RealXMLReportWriter(reportFileWriter); 96 try { 97 reportFileWriter.write("<JesterReport>\n"); 99 ProgressReporter progressReporter = mainArguments.shouldShowProgressDialog() ? 100 new RealProgressReporter(configuration) : 101 (ProgressReporter) new NullProgressReporter(); aReport = new RealReport(configuration, new PrintWriter(System.out), anXMLReportWriter, progressReporter); 103 104 String [] directoryNames = mainArguments.getDirectoryOrFileNames(); 105 ClassIterator classIterator = new FileBasedClassIterator(configuration, directoryNames, aReport); 106 107 String testClassName = mainArguments.getTestClassName(); 108 TestRunner testRunner = new RealTestRunner(configuration, testClassName); 109 110 ClassTestTester classTestTester = new RealClassTestTester(testRunner, new RealMutationsList(RealMutationsList.DEFAULT_MUTATIONS_FILENAME)); 111 112 TestTester testTester = new TestTester(testRunner, classIterator, classTestTester); 113 testTester.run(); 114 } finally { 115 reportFileWriter.write("</JesterReport>"); 116 reportFileWriter.close(); 117 } 118 long t2 = System.currentTimeMillis(); 119 if (aReport != null) { 120 System.out.println(aReport); 121 } 122 long runTime = t2-t1; 123 return runTime; 124 } 125 126 public void run() throws SourceChangeException { 127 boolean testsPassedBeforeAnyChanges = testRunner.testsRunWithoutFailures(); 128 if (!testsPassedBeforeAnyChanges) { 129 throw new SourceChangeException("Couldn't run test tester because tests didn't pass before any changes made - see FAQ referenced at http://www.jesterinfo.co.uk"); 130 } 131 classIterator.iterate(classTestTester); 132 } 133 134 private static void deleteTimeoutFile() { 135 File timeoutFile = new File(TIMEOUT_FILENAME); 136 if (timeoutFile.exists()) { 137 timeoutFile.delete(); 138 } 139 } 140 } | Popular Tags |