001: /* BaseFormatter.java */
002:
003: // //////////////////////////////////////////////////////////////////
004: // NEEDS DOCUMENTATION //////////////////////////////////////////////
005: // //////////////////////////////////////////////////////////////////
006: package org.quilt.reports;
007:
008: import java.io.IOException;
009: import java.io.OutputStream;
010: import java.io.PrintWriter;
011: import java.io.StringWriter;
012: import java.text.NumberFormat;
013:
014: import junit.framework.*;
015:
016: import org.apache.tools.ant.BuildException;
017:
018: import org.quilt.framework.*;
019: import org.quilt.runner.Runner;
020:
021: /**
022: * Basic test result formatter for Ant/Quilt/JUnit.
023: */
024: public abstract class BaseFormatter implements Formatter {
025:
026: protected boolean filtertrace = true;
027: protected NumberFormat numberFormat = NumberFormat.getInstance();
028: protected OutputStream out;
029: protected PrintWriter output;
030: protected Runner runner = null;
031: protected StringWriter results;
032: protected PrintWriter resultWriter;
033: protected String systemError = null;
034: protected String systemOutput = null;
035:
036: /**
037: * Root around in a junit Test and find a getName method.
038: *
039: * Test may be TestCase or TestSuite; in either case there will be a
040: * getName method in JUnit 3.7 or later.
041: *
042: * @return Test/suite name.
043: */
044: public static String getTestName(Test test) {
045: if (test instanceof TestSuite) {
046: return ((TestSuite) test).getName();
047: } else if (test instanceof TestCase) {
048: return ((TestCase) test).getName();
049: } else {
050: return "unknown";
051: }
052: }
053:
054: // INTERFACE FORMATTER //////////////////////////////////////////
055: // Formatter extends JUnit TestListener; these are the extra ////
056: // methods. /////////////////////////////////////////////////////
057:
058: /** Called at end of Quilt/JUnit test run. */
059: public void endTestSuite(QuiltTest suite) throws BuildException {
060: }
061:
062: /** Whether to filter Ant/Quilt/JUnit lines from stack traces. */
063: public void setFiltertrace(boolean b) {
064: filtertrace = b;
065: }
066:
067: /** Where to send the report output. */
068: public void setOutput(OutputStream out) {
069: this .out = out;
070: output = new PrintWriter(out);
071: }
072:
073: /** Determines which test runner to use. */
074: public void setRunner(Runner testrunner) {
075: runner = testrunner;
076: }
077:
078: /** Where to send system output. */
079: public void setSystemOutput(String out) {
080: systemOutput = out;
081: }
082:
083: /** Where to send system error output. */
084: public void setSystemError(String err) {
085: systemError = err;
086: }
087:
088: /** Called at the start of the Ant/Quilt/JUnit test run. */
089: public void startTestSuite(QuiltTest suite) throws BuildException {
090: }
091:
092: // INTERFACE TESTLISTENER ///////////////////////////////////////
093: // Stubs for the JUnit TestListener methods /////////////////////
094:
095: /** A test caused an unexpected error. */
096: public void addError(Test test, Throwable error) {
097: }
098:
099: /** A test failed. */
100: public void addFailure(Test test, Throwable t) {
101: }
102:
103: /** A test failed. */
104: public void addFailure(Test test, AssertionFailedError t) {
105: addFailure(test, (Throwable) t);
106: }
107:
108: /**
109: * Method called at beginning of test.
110: * @param test JUnit Test (TestCase or TestSuite)
111: */
112: public void startTest(Test test) {
113: }
114:
115: /**
116: * Method called at end of test.
117: * @param test JUnit Test (TestCase or TestSuite)
118: */
119: public void endTest(Test test) {
120: }
121: }
|