View Javadoc
1 /* BaseFormatter.java */ 2 3 // ////////////////////////////////////////////////////////////////// 4 // NEEDS DOCUMENTATION ////////////////////////////////////////////// 5 // ////////////////////////////////////////////////////////////////// 6 7 package org.quilt.reports; 8 9 import java.io.IOException; 10 import java.io.OutputStream; 11 import java.io.PrintWriter; 12 import java.io.StringWriter; 13 import java.text.NumberFormat; 14 15 import junit.framework.*; 16 17 import org.apache.tools.ant.BuildException; 18 19 import org.quilt.framework.*; 20 import org.quilt.runner.Runner; 21 22 /*** 23 * Basic test result formatter for Ant/Quilt/JUnit. 24 */ 25 public abstract class BaseFormatter implements Formatter { 26 27 protected boolean filtertrace = true; 28 protected NumberFormat numberFormat = NumberFormat.getInstance(); 29 protected OutputStream out; 30 protected PrintWriter output; 31 protected Runner runner = null; 32 protected StringWriter results; 33 protected PrintWriter resultWriter; 34 protected String systemError = null; 35 protected String systemOutput = null; 36 37 /*** 38 * Root around in a junit Test and find a getName method. 39 * 40 * Test may be TestCase or TestSuite; in either case there will be a 41 * getName method in JUnit 3.7 or later. 42 * 43 * @return Test/suite name. 44 */ 45 public static String getTestName (Test test) { 46 if ( test instanceof TestSuite ) { 47 return ( (TestSuite) test ) . getName(); 48 } else if ( test instanceof TestCase ) { 49 return ( (TestCase) test ) . getName(); 50 } else { 51 return "unknown"; 52 } 53 } 54 // INTERFACE FORMATTER ////////////////////////////////////////// 55 // Formatter extends JUnit TestListener; these are the extra //// 56 // methods. ///////////////////////////////////////////////////// 57 58 /*** Called at end of Quilt/JUnit test run. */ 59 public void endTestSuite(QuiltTest suite) throws BuildException {} 60 61 /*** Whether to filter Ant/Quilt/JUnit lines from stack traces. */ 62 public void setFiltertrace (boolean b) { 63 filtertrace = b; 64 } 65 66 /*** Where to send the report output. */ 67 public void setOutput(OutputStream out) { 68 this.out = out; 69 output = new PrintWriter(out); 70 } 71 72 /*** Determines which test runner to use. */ 73 public void setRunner(Runner testrunner) { 74 runner = testrunner; 75 } 76 77 /*** Where to send system output. */ 78 public void setSystemOutput(String out) { 79 systemOutput = out; 80 } 81 82 /*** Where to send system error output. */ 83 public void setSystemError(String err) { 84 systemError = err; 85 } 86 87 /*** Called at the start of the Ant/Quilt/JUnit test run. */ 88 public void startTestSuite(QuiltTest suite) throws BuildException {} 89 90 // INTERFACE TESTLISTENER /////////////////////////////////////// 91 // Stubs for the JUnit TestListener methods ///////////////////// 92 93 /*** A test caused an unexpected error. */ 94 public void addError(Test test, Throwable error) {} 95 96 /*** A test failed. */ 97 public void addFailure(Test test, Throwable t) {} 98 99 /*** A test failed. */ 100 public void addFailure(Test test, AssertionFailedError t) { 101 addFailure(test, (Throwable) t); 102 } 103 104 /*** 105 * Method called at beginning of test. 106 * @param test JUnit Test (TestCase or TestSuite) 107 */ 108 public void startTest(Test test) { } 109 /*** 110 * Method called at end of test. 111 * @param test JUnit Test (TestCase or TestSuite) 112 */ 113 public void endTest(Test test) { } 114 }

This page was automatically generated by Maven