KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jester > TestTester


1 package jester;
2
3 import java.io.*;
4
5 /**
6  * Copyright (2000-2005) Ivan Moore
7  *
8  * see http://jester.sourceforge.net
9  * for updates, FAQs etc.
10  *
11  * JUnit Software and Software Derivatives are available only
12  * under the terms of the JUnit licence.
13  *
14  * This software is only available under the terms of its licence:
15  *
16  * Copyright (c) 2000-2005 Ivan Moore
17
18     All rights reserved.
19
20     Permission is hereby granted, free of charge, to any person obtaining a
21     copy of this software and associated documentation files (the
22     "Software"), to deal in the Software without restriction, including
23     without limitation the rights to use, copy, modify, merge, publish,
24     distribute, and/or sell copies of the Software, and to permit persons
25     to whom the Software is furnished to do so, provided that the above
26     copyright notice(s) and this permission notice appear in all copies of
27     the Software and that both the above copyright notice(s) and this
28     permission notice appear in supporting documentation.
29
30     THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
31     OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
32     MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
33     OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
34     HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
35     INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
36     FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
37     NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
38     WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
39
40     Except as contained in this notice, the name of a copyright holder
41     shall not be used in advertising or otherwise to promote the sale, use
42     or other dealings in this Software without prior written authorization
43     of the copyright holder.
44  */

45
46 public class TestTester {
47     public static final String JavaDoc VERSION = "1.37";
48
49     public static final String JavaDoc 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 JavaDoc args[]) {
64         try {
65             try {
66                 mainArguments = new MainArguments(args, new FileExistenceChecker(){
67                     public boolean exists(String JavaDoc 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 JavaDoc 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");//can be tidied up - XMLReportWriter should do this
98

99             ProgressReporter progressReporter = mainArguments.shouldShowProgressDialog() ?
100                                                 new RealProgressReporter(configuration) :
101                             (ProgressReporter) new NullProgressReporter();//the cast should not be necessary but eclipse's compiler thought it was
102
aReport = new RealReport(configuration, new PrintWriter(System.out), anXMLReportWriter, progressReporter);
103
104             String JavaDoc[] directoryNames = mainArguments.getDirectoryOrFileNames();
105             ClassIterator classIterator = new FileBasedClassIterator(configuration, directoryNames, aReport);
106
107             String JavaDoc 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