Run junit automation tests on LambdaTest cloud grid
Perform automation testing on 3000+ real desktop and mobile devices online.
package utfx.printers;
import java.io.OutputStream;
import java.util.Enumeration;
import junit.framework.*;
import junit.runner.BaseTestRunner;
/**
* Simple result printer which produces output similar to that of
* <code>junit.textui.ResultPrinter</code>. This result printer is based on
* <code>junit.textui.ResultPrinter</code> by Kent Beck and Erich Gamma.
*
* <p>
* Copyright © 2004 - <a href="http://www.usq.edu.au"> University of
* Southern Queensland. </a>
* </p>
*
* <p>
* This program is free software; you can redistribute it and/or modify it under
* the terms of the <a href="http://www.gnu.org/licenses/gpl.txt">GNU General
* Public License v2 </a> as published by the Free Software Foundation.
* </p>
*
* <p>
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* </p>
*
* <code>
* $Source: /cvs/utf-x/framework/src/java/utfx/printers/JunitResultPrinter.java,v $
* </code>
*
* @author Jacek Radajewski
* @author Kent Beck and Erich Gamma (authors of
* <code>junit.textui.ResultPrinter</code>)
* @version $Revision$ $Date$ $Name: $
*/
public class JunitResultPrinter extends ResultPrinter {
/** column number */
private int colNum = 0;
public JunitResultPrinter(OutputStream os) {
super(os);
}
/**
* Print summary header.
*
* Based on <code>junit.textui.ResultPrinter</code> by Kent Beck and Erich
* Gamma.
*
* @see junit.textui.ResultPrinter
*/
public void printHeader(TestResult result) {
println();
print("Time: ");
printElapsedTimeMillis();
println();
}
/**
* Print errors.
*
* Based on <code>junit.textui.ResultPrinter</code> by Kent Beck and Erich
* Gamma.
*
* @see junit.textui.ResultPrinter
*/
public void printErrors(TestResult result) {
printDefects(result.errors(), result.errorCount(), "error");
}
/**
* Print failures
*
* Based on <code>junit.textui.ResultPrinter</code> by Kent Beck and Erich
* Gamma.
*
* @see junit.textui.ResultPrinter
*/
public void printFailures(TestResult result) {
printDefects(result.failures(), result.failureCount(), "failure");
}
/**
* Print defects.
*
* Based on <code>junit.textui.ResultPrinter</code> by Kent Beck and Erich
* Gamma.
*
* @see junit.textui.ResultPrinter
*/
public void printDefects(Enumeration booBoos, int count, String type) {
if (count == 0) {
return;
}
if (count == 1) {
println("There was " + count + " " + type + ":");
} else {
println("There were " + count + " " + type + "s:");
}
for (int i = 1; booBoos.hasMoreElements(); i++) {
printDefect((TestFailure) booBoos.nextElement(), i);
}
}
/**
* Print a defect.
*
* Based on <code>junit.textui.ResultPrinter</code> by Kent Beck and Erich
* Gamma.
*
* @see junit.textui.ResultPrinter
*/
public void printDefect(TestFailure booBoo, int count) {
printDefectHeader(booBoo, count);
printDefectTrace(booBoo);
}
/**
* Print defect header.
*
* Based on <code>junit.textui.ResultPrinter</code> by Kent Beck and Erich
* Gamma.
*
* @see junit.textui.ResultPrinter
*/
public void printDefectHeader(TestFailure booBoo, int count) {
print("[" + count + "] " + booBoo.failedTest());
}
/**
* Print defect trace.
*
* Based on <code>junit.textui.ResultPrinter</code> by Kent Beck and Erich
* Gamma.
*
* @see junit.textui.ResultPrinter
*/
public void printDefectTrace(TestFailure booBoo) {
print(BaseTestRunner.getFilteredTrace(booBoo.trace()));
}
/**
* Print footer.
*
* Based on <code>junit.textui.ResultPrinter</code> by Kent Beck and Erich
* Gamma.
*
* @see junit.textui.ResultPrinter
*/
public void printFooter(TestResult result) {
if (result.wasSuccessful()) {
println();
print("OK");
println(" (" + result.runCount() + " test"
+ (result.runCount() == 1 ? "" : "s") + ")");
} else {
println();
println("FAILURES!!!");
println("Tests run: " + result.runCount() + ", Failures: "
+ result.failureCount() + ", Errors: "
+ result.errorCount());
}
println();
}
/**
* Print error symbol.
*
* Based on <code>junit.textui.ResultPrinter</code> by Kent Beck and Erich
* Gamma.
*
* @see junit.textui.ResultPrinter
* @see junit.framework.TestListener#addError(Test, Throwable)
*/
public void addError(Test test, Throwable t) {
print('E');
}
/**
* Print failure symbol.
*
* Based on <code>junit.textui.ResultPrinter</code> by Kent Beck and Erich
* Gamma.
*
* @see junit.textui.ResultPrinter
* @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)
*/
public void addFailure(Test test, AssertionFailedError t) {
print('F');
}
/**
* Start of a test case.
*
* @param testCase the TestSuite we are entering.
*/
public void startTestCase(TestCase testCase) {
print('.');
// just like the original Junit printer we only print up to 40
// columns wide
if (colNum++ >= 40) {
println();
colNum = 0;
}
}
/**
* End of a test case.
*
* @param testCase
*/
public void endTestCase(TestCase testCase) {
// nothing to do here
}
/**
* Start of a test suite.
*
* @param suite the TestSuite we are entering.
*/
public void startTestSuite(TestSuite suite) {
// nothing to do here
}
/**
* End of a test suite.
*
* @param suite the TestSuite we are leaving
*/
public void endTestSuite(TestSuite suite) {
// nothing to do here
}
}
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.uima.test.junit_extension;
import java.io.PrintStream;
import java.text.NumberFormat;
import java.util.Enumeration;
import junit.framework.AssertionFailedError;
import junit.framework.Test;
import junit.framework.TestFailure;
import junit.framework.TestListener;
import junit.framework.TestResult;
import junit.runner.BaseTestRunner;
import junit.textui.ResultPrinter;
/**
* UIMAResultPrinter is a ResultPrinter extension for the JUnit framework.
*/
public class UIMAResultPrinter extends ResultPrinter implements TestListener {
// print stream for the output
private PrintStream fWriter;
// current column in line
private int fColumn = 0;
// test case counter
private int testCounter;
// name of the current test class
private String currentTestClass;
// success status of the current test method
private boolean currentTestSuccess;
// abort execution if an error occurs
private boolean abortOnFail;
// dublicated output stream, change output layout
private boolean teeOutputStream;
public UIMAResultPrinter(PrintStream writer, boolean abortOnFail, boolean teeOutputStream) {
// init class members
super(writer);
this.fWriter = writer;
this.testCounter = 0;
this.currentTestClass = null;
this.currentTestSuccess = true;
this.abortOnFail = abortOnFail;
this.teeOutputStream = teeOutputStream;
}
/**
* @see junit.textui.ResultPrinter#printHeader(long)
*/
@Override
protected void printHeader(long runTime) {
getWriter().println();
getWriter().println();
getWriter().println("Time: " + elapsedTimeAsString(runTime));
}
/**
* @see junit.textui.ResultPrinter#printErrors(junit.framework.TestResult)
*/
@Override
protected void printErrors(TestResult result) {
printDefects(result.errors(), result.errorCount(), "error");
}
/**
* @see junit.textui.ResultPrinter#printFailures(junit.framework.TestResult)
*/
@Override
protected void printFailures(TestResult result) {
printDefects(result.failures(), result.failureCount(), "failure");
}
/**
* @see junit.textui.ResultPrinter#printDefects(java.util.Enumeration, int, java.lang.String)
*/
@Override
protected void printDefects(Enumeration booBoos, int count, String type) {
if (count == 0)
return;
if (count == 1)
getWriter().println("There was " + count + " " + type + ":");
else
getWriter().println("There were " + count + " " + type + "s:");
for (int i = 1; booBoos.hasMoreElements(); i++) {
printDefect((TestFailure) booBoos.nextElement(), i);
}
}
/**
* @see junit.textui.ResultPrinter#printDefect(junit.framework.TestFailure, int)
*/
@Override
public void printDefect(TestFailure booBoo, int count) { // only public for testing purposes
printDefectHeader(booBoo, count);
printDefectTrace(booBoo);
}
/**
* @see junit.textui.ResultPrinter#printDefectHeader(junit.framework.TestFailure, int)
*/
@Override
protected void printDefectHeader(TestFailure booBoo, int count) {
// I feel like making this a println, then adding a line giving the throwable a chance to print
// something
// before we get to the stack trace.
getWriter().print(count + ") " + booBoo.failedTest());
}
/**
* @see junit.textui.ResultPrinter#printDefectTrace(junit.framework.TestFailure)
*/
@Override
protected void printDefectTrace(TestFailure booBoo) {
getWriter().print(BaseTestRunner.getFilteredTrace(booBoo.trace()));
}
/**
* @see junit.textui.ResultPrinter#printFooter(junit.framework.TestResult)
*/
@Override
protected void printFooter(TestResult result) {
if (result.wasSuccessful()) {
getWriter().println();
getWriter().print("OK");
getWriter().println(
" (" + result.runCount() + " test" + (result.runCount() == 1 ? "" : "s") + ")");
} else {
getWriter().println();
getWriter().println("FAILURES!!!");
getWriter().println("Tests run: " + result.runCount() + ", Failures: "
+ result.failureCount() + ", Errors: " + result.errorCount());
}
getWriter().println();
}
/**
* Returns the formatted string of the elapsed time. Duplicated from BaseTestRunner. Fix it.
*/
@Override
protected String elapsedTimeAsString(long runTime) {
return NumberFormat.getInstance().format((double) runTime / 1000);
}
/**
* @see junit.textui.ResultPrinter#getWriter()
*/
@Override
public PrintStream getWriter() {
return this.fWriter;
}
/**
* @see junit.framework.TestListener#addError(Test, Throwable)
*/
@Override
public void addError(Test test, Throwable t) {
getWriter().print("error");
this.currentTestSuccess = false;
if (this.abortOnFail) {
getWriter().println();
getWriter().println();
getWriter().println("Stop executing testcases...");
getWriter().println("Print Stacktrace: ");
getWriter().println();
StackTraceElement[] stackTrace = t.getStackTrace();
for (int i = 0; i < stackTrace.length; i++) {
getWriter().println(stackTrace[i].toString());
}
throw new RuntimeException("Abort on error");
}
}
/**
* @see junit.framework.TestListener#addFailure(Test, AssertionFailedError)
*/
@Override
public void addFailure(Test test, AssertionFailedError t) {
getWriter().print("failure");
this.currentTestSuccess = false;
if (this.abortOnFail) {
getWriter().println();
getWriter().println();
getWriter().println("Stop executing testcases...");
getWriter().println("Print Stacktrace: ");
getWriter().println();
StackTraceElement[] stackTrace = t.getStackTrace();
for (int i = 0; i < stackTrace.length; i++) {
getWriter().println(stackTrace[i].toString());
}
throw new RuntimeException("Abort on failure");
}
}
/**
* @see junit.framework.TestListener#endTest(Test)
*/
@Override
public void endTest(Test test) {
if (this.currentTestSuccess == false)
this.currentTestSuccess = true;
else
getWriter().print("ok");
}
/**
* @see junit.framework.TestListener#startTest(Test)
*/
@Override
public void startTest(Test test) {
this.testCounter++;
String name = test.toString();
String tempCurrentTestClass = name.substring(name.indexOf('(') + 1, name.lastIndexOf(')'));
String testName = name.substring(0, name.indexOf('('));
if (!tempCurrentTestClass.equals(this.currentTestClass)) {
this.currentTestClass = tempCurrentTestClass;
getWriter().println();
getWriter().println();
getWriter().print(this.currentTestClass);
getWriter().println();
for (int i = 0; i < this.currentTestClass.length(); i++)
getWriter().print("=");
}
getWriter().println();
getWriter().print(this.testCounter + ": " + testName + ": ");
if (this.fColumn++ >= 40 || this.teeOutputStream) {
getWriter().println();
this.fColumn = 0;
}
}
}
/* */ package junit.textui;
/* */
/* */ import java.io.PrintStream;
/* */ import java.text.NumberFormat;
/* */ import java.util.Enumeration;
/* */ import junit.framework.AssertionFailedError;
/* */ import junit.framework.Test;
/* */ import junit.framework.TestFailure;
/* */ import junit.framework.TestListener;
/* */ import junit.framework.TestResult;
/* */ import junit.runner.BaseTestRunner;
/* */
/* */ public class ResultPrinter
/* */ implements TestListener {
/* */ PrintStream fWriter;
/* 16 */ int fColumn = 0;
/* */
/* */ public ResultPrinter(PrintStream writer) {
/* 19 */ this.fWriter = writer;
/* */ }
/* */
/* */
/* */
/* */ synchronized void print(TestResult result, long runTime) {
/* 25 */ printHeader(runTime);
/* 26 */ printErrors(result);
/* 27 */ printFailures(result);
/* 28 */ printFooter(result);
/* */ }
/* */
/* */ void printWaitPrompt() {
/* 32 */ getWriter().println();
/* 33 */ getWriter().println("<RETURN> to continue");
/* */ }
/* */
/* */
/* */
/* */ protected void printHeader(long runTime) {
/* 39 */ getWriter().println();
/* 40 */ getWriter().println("Time: " + elapsedTimeAsString(runTime));
/* */ }
/* */
/* */ protected void printErrors(TestResult result) {
/* 44 */ printDefects(result.errors(), result.errorCount(), "error");
/* */ }
/* */
/* */ protected void printFailures(TestResult result) {
/* 48 */ printDefects(result.failures(), result.failureCount(), "failure");
/* */ }
/* */
/* */ protected void printDefects(Enumeration<TestFailure> booBoos, int count, String type) {
/* 52 */ if (count == 0)
/* 53 */ return; if (count == 1) {
/* 54 */ getWriter().println("There was " + count + " " + type + ":");
/* */ } else {
/* 56 */ getWriter().println("There were " + count + " " + type + "s:");
/* */ }
/* 58 */ for (int i = 1; booBoos.hasMoreElements(); i++) {
/* 59 */ printDefect(booBoos.nextElement(), i);
/* */ }
/* */ }
/* */
/* */ public void printDefect(TestFailure booBoo, int count) {
/* 64 */ printDefectHeader(booBoo, count);
/* 65 */ printDefectTrace(booBoo);
/* */ }
/* */
/* */
/* */
/* */ protected void printDefectHeader(TestFailure booBoo, int count) {
/* 71 */ getWriter().print(count + ") " + booBoo.failedTest());
/* */ }
/* */
/* */ protected void printDefectTrace(TestFailure booBoo) {
/* 75 */ getWriter().print(BaseTestRunner.getFilteredTrace(booBoo.trace()));
/* */ }
/* */
/* */ protected void printFooter(TestResult result) {
/* 79 */ if (result.wasSuccessful()) {
/* 80 */ getWriter().println();
/* 81 */ getWriter().print("OK");
/* 82 */ getWriter().println(" (" + result.runCount() + " test" + ((result.runCount() == 1) ? "" : "s") + ")");
/* */ } else {
/* */
/* 85 */ getWriter().println();
/* 86 */ getWriter().println("FAILURES!!!");
/* 87 */ getWriter().println("Tests run: " + result.runCount() + ", Failures: " + result.failureCount() + ", Errors: " + result.errorCount());
/* */ }
/* */
/* */
/* 91 */ getWriter().println();
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ protected String elapsedTimeAsString(long runTime) {
/* 99 */ return NumberFormat.getInstance().format(runTime / 1000.0D);
/* */ }
/* */
/* */ public PrintStream getWriter() {
/* 103 */ return this.fWriter;
/* */ }
/* */
/* */
/* */
/* */
/* */ public void addError(Test test, Throwable e) {
/* 110 */ getWriter().print("E");
/* */ }
/* */
/* */
/* */
/* */
/* */ public void addFailure(Test test, AssertionFailedError t) {
/* 117 */ getWriter().print("F");
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */ public void endTest(Test test) {}
/* */
/* */
/* */
/* */
/* */ public void startTest(Test test) {
/* 130 */ getWriter().print(".");
/* 131 */ if (this.fColumn++ >= 40) {
/* 132 */ getWriter().println();
/* 133 */ this.fColumn = 0;
/* */ }
/* */ }
/* */ }
/* Location: /home/arpit/Downloads/Picking-Tool-6.5.2.jar!/junit/textui/ResultPrinter.class
* Java compiler version: 5 (49.0)
* JD-Core Version: 1.1.3
*/
Accelerate Your Automation Test Cycles With LambdaTest
Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.