blob: 816bf2c80340b706d44b672121922513011ab215 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
/*******************************************************************************
* Copyright (c) 2000, 2008 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.debug.jdi.tests;
import java.util.Enumeration;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestFailure;
import junit.framework.TestResult;
/**
* Tests a <code>TestResult</code>
*/
public class TextTestResult extends TestResult {
/**
* @see junit.framework.TestResult#addError(junit.framework.Test, java.lang.Throwable)
*/
@Override
public synchronized void addError(Test test, Throwable t) {
super.addError(test, t);
System.out.println("E");
}
/**
* @see junit.framework.TestResult#addFailure(junit.framework.Test, junit.framework.AssertionFailedError)
*/
@Override
public synchronized void addFailure(Test test, AssertionFailedError t) {
super.addFailure(test, t);
System.out.print("F");
}
/**
* Prints failures to the standard output
*/
public synchronized void print() {
printHeader();
printErrors();
printFailures();
}
/**
* Prints the errors to the standard output
*/
public void printErrors() {
if (errorCount() != 0) {
if (errorCount() == 1)
System.out.println("There was " + errorCount() + " error:");
else
System.out.println("There were " + errorCount() + " errors:");
int i = 1;
for (Enumeration e = errors(); e.hasMoreElements(); i++) {
TestFailure failure = (TestFailure) e.nextElement();
System.out.println(i + ") " + failure.failedTest());
failure.thrownException().printStackTrace();
System.out.println();
}
}
}
/**
* Prints failures to the standard output
*/
public void printFailures() {
if (failureCount() != 0) {
if (failureCount() == 1)
System.out.println("There was " + failureCount() + " failure:");
else
System.out.println(
"There were " + failureCount() + " failures:");
int i = 1;
for (Enumeration e = failures(); e.hasMoreElements(); i++) {
TestFailure failure = (TestFailure) e.nextElement();
System.out.print(i + ") " + failure.failedTest());
Throwable t = failure.thrownException();
if (t.getMessage() != null)
System.out.println(" \"" + t.getMessage() + "\"");
else {
System.out.println();
failure.thrownException().printStackTrace();
}
}
}
}
/**
* Prints the header of the report
*/
public void printHeader() {
if (wasSuccessful()) {
System.out.println();
System.out.print("OK");
System.out.println(" (" + runCount() + " tests)");
} else {
System.out.println();
System.out.println("!!!FAILURES!!!");
System.out.println("Test Results:");
System.out.println(
"Run: "
+ runCount()
+ " Failures: "
+ failureCount()
+ " Errors: "
+ errorCount());
}
}
/**
* @see junit.framework.TestResult#startTest(junit.framework.Test)
*/
@Override
public synchronized void startTest(Test test) {
super.startTest(test);
System.out.print(".");
}
}
|