001: /*
002: *
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
004: *
005: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
006: *
007: * The contents of this file are subject to the terms of either the GNU
008: * General Public License Version 2 only ("GPL") or the Common
009: * Development and Distribution License("CDDL") (collectively, the
010: * "License"). You may not use this file except in compliance with the
011: * License. You can obtain a copy of the License at
012: * http://www.netbeans.org/cddl-gplv2.html
013: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
014: * specific language governing permissions and limitations under the
015: * License. When distributing the software, include this License Header
016: * Notice in each file and include the License file at
017: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
018: * particular file as subject to the "Classpath" exception as provided
019: * by Sun in the GPL Version 2 section of the License file that
020: * accompanied this code. If applicable, add the following below the
021: * License Header, with the fields enclosed by brackets [] replaced by
022: * your own identifying information:
023: * "Portions Copyrighted [year] [name of copyright owner]"
024: *
025: * Contributor(s):
026: *
027: * The Original Software is NetBeans. The Initial Developer of the Original
028: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
029: * Microsystems, Inc. All Rights Reserved.
030: *
031: * If you wish your version of this file to be governed by only the CDDL
032: * or only the GPL Version 2, indicate your decision by adding
033: * "[Contributor] elects to include this software in this distribution
034: * under the [CDDL or GPL Version 2] license." If you do not indicate a
035: * single choice of license, a recipient has the option to distribute
036: * your version of this file under either the CDDL, the GPL Version 2 or
037: * to extend the choice of license to its licensees as provided above.
038: * However, if you add GPL Version 2 code and therefore, elected the GPL
039: * Version 2 license, then the option applies only if the new code is
040: * made subject to such option by the copyright holder.
041: */
042:
043: /*
044: * ConsoleSummaryReporter.java
045: *
046: * Created on November 1, 2001, 3:34 PM
047: */
048:
049: package org.netbeans.xtest.testrunner;
050:
051: import java.io.*;
052:
053: import junit.framework.*;
054:
055: import java.text.*;
056: import org.netbeans.junit.NbTest;
057:
058: /**
059: *
060: * @author mb115822
061: * @version
062: */
063:
064: public class ConsoleSummaryReporter implements JUnitTestListener {
065:
066: // output stream
067: private PrintWriter pw;
068: // text formatters
069: DecimalFormat percentFormatter = new DecimalFormat("##0.00%");
070: DecimalFormat timeFormatter = new DecimalFormat("#######0.000");
071:
072: // suiteStartTime
073: private long suiteStartTime;
074:
075: private int expectedFailCount = 0;
076:
077: private int xtestErrorManagerCorrection = 0;
078: private boolean failureAlreadySet;
079:
080: public ConsoleSummaryReporter() {
081: this .pw = new PrintWriter(System.out);
082: }
083:
084: public ConsoleSummaryReporter(PrintWriter pw) {
085: this .pw = pw;
086: }
087:
088: public ConsoleSummaryReporter(PrintStream ps) {
089: this .pw = new PrintWriter(ps);
090: }
091:
092: public void startTestSuite(TestSuite suite) {
093: suiteStartTime = System.currentTimeMillis();
094: expectedFailCount = 0;
095: pw.println("- test suite " + suite.getName() + " started");
096: pw.flush();
097: }
098:
099: public void endTestSuite(TestSuite suite, TestResult suiteResult) {
100: long suiteDelta = System.currentTimeMillis() - suiteStartTime;
101: int failCount = suiteResult.failureCount()
102: - xtestErrorManagerCorrection;
103: int passCount = suiteResult.runCount() - failCount
104: - suiteResult.errorCount();
105: if (passCount < 0) {
106: passCount = 0;
107: }
108: if (passCount != suiteResult.runCount()) {
109: pw.println("- test suite " + suite.getName() + " FAILED");
110: pw.println("- time elapsed: "
111: + timeFormatter.format(suiteDelta / 1000.0)
112: + " seconds");
113: pw.print("- passed: " + passCount + " failed: "
114: + failCount);
115: if (expectedFailCount > 0)
116: pw.print(" (incl. " + expectedFailCount + " expected)");
117: pw.println(" errors: " + suiteResult.errorCount()
118: + " total: " + suiteResult.runCount());
119: double successRate = 0;
120: if (suiteResult.runCount() != 0) {
121: successRate = ((double) passCount)
122: / ((double) suiteResult.runCount());
123: }
124: pw.println("- success rate: "
125: + percentFormatter.format(successRate));
126: } else {
127: pw.println("- test suite " + suite.getName() + " passed: "
128: + passCount + " test(s)");
129: pw.println("- time elapsed: "
130: + timeFormatter.format(suiteDelta / 1000.0)
131: + " seconds");
132: }
133: pw.print('\n');
134: pw.flush();
135: }
136:
137: // empty
138: public void startTest(Test t) {
139: failureAlreadySet = false;
140: }
141:
142: // empty
143: public void endTest(Test test) {
144: }
145:
146: // empty
147: public void addFailure(Test test, AssertionFailedError t) {
148: failureAlreadySet = true;
149: if (test instanceof NbTest) {
150: if (((NbTest) test).getExpectedFail() != null)
151: expectedFailCount++;
152: }
153: }
154:
155: // empty
156: public void addError(Test test, Throwable t) {
157: if (failureAlreadySet) {
158: // error added by XTestErrorManager and we have to subtract one fail
159: xtestErrorManagerCorrection++;
160: }
161: }
162:
163: // empty
164: public void setOutputFile(java.io.File outFile) {
165: }
166:
167: }
|