Source code: com/simscomputing/testbed/DefaultReporter.java
1 // Java Test Bed: tools for testing Java classes
2 // Copyright 1999 Sims Computing
3 // This software is licensed under the GNU General Public License,
4 // available at http://www.gnu.org/copyleft/gpl.html.
5
6 package com.simscomputing.testbed;
7
8 import java.util.Iterator;
9 import java.util.SortedMap;
10
11 /**
12 A reporter that writes its result to stdout.
13
14 @author David Sims
15 @version $Revision: 1.1.1.1 $ $Date: 2000/02/21 21:22:33 $
16 */
17 public class DefaultReporter implements Reporter {
18 /**
19 Extracts test results from 'tester' and sends the results to stdout.
20
21 @param Tester - a tester that has already exercised a class
22 */
23 public void report(TestResultCollection testResultCollection) {
24 Iterator iterator = testResultCollection.getIterator();
25 if (iterator == null) {
26 return;
27 } // if
28
29 TestResult testResult;
30
31 // we would prefer to iterate over methods in lexicographic order
32 while (iterator.hasNext()) {
33 testResult = (TestResult) iterator.next();
34 if (testResult.didTestPass()) {
35 System.out.println(testResult.getLongName() + ": passed, " +
36 testResult.getExecutionTimeInMilliseconds() +
37 " milliseconds");
38 } // if
39 else {
40 if (testResult.didTestFailAbnormally()) {
41 System.out.println(testResult.getLongName() + ": failed abnormally:");
42 testResult.getTestFailureException().printStackTrace(System.out);
43 System.out.println();
44 } // if
45 else {
46 System.out.println(testResult.getLongName() + ": failed, " +
47 testResult.getTestFailureDescription());
48 } // else
49 } // else
50 } // while
51
52 if (testResultCollection.didAllTestsPass()) {
53 System.out.println("\nAll " + testResultCollection.getNumberOfTests() + " tests passed");
54 } // if
55 else {
56 System.out.println("\n" + testResultCollection.getNumberOfTestsThatPassed() + " tests passed, " +
57 (testResultCollection.getNumberOfTests() - testResultCollection.getNumberOfTestsThatPassed()) + " tests failed");
58 } // else
59 System.out.println("Cumulative testing time = " +
60 testResultCollection.getCumulativeTestExecutionTimeInMilliseconds() +
61 " milliseconds");
62 } // report()
63 } // class DefaultReporter