1 2 3 7 package org.quilt.reports; 8 9 import java.text.NumberFormat ; 10 import java.io.IOException ; 11 import java.io.OutputStream ; 12 13 import junit.framework.AssertionFailedError; 14 import junit.framework.Test; 15 16 import org.apache.tools.ant.BuildException; 17 18 import org.quilt.framework.*; 19 import org.quilt.runner.Runner; 20 21 public class SummaryFormatter implements Formatter { 22 23 private boolean filtertrace = false; 24 private Runner runner = null; 25 26 private NumberFormat nf = NumberFormat.getInstance(); 27 private OutputStream out; 28 29 private boolean withOutAndErr = false; 30 private String systemOutput = null; 31 private String systemError = null; 32 33 public SummaryFormatter() {} 34 35 37 38 public void endTestSuite(QuiltTest qt) throws BuildException { 39 StringBuffer sb = new StringBuffer ("Tests run: " + qt.runCount() 40 + ", Failures: " + qt.failureCount() 41 + ", Errors: " + qt.errorCount() 42 + ", Time elapsed: "+ nf.format(qt.getRunTime() / 1000.0) 43 + " sec\n" ); 44 45 if (withOutAndErr) { 46 if (systemOutput != null && systemOutput.length() > 0) { 47 sb.append("Output:\n" + systemOutput + "\n"); 48 } 49 if (systemError != null && systemError.length() > 0) { 50 sb.append("Error:\n " + systemError + "\n"); 51 } 52 } 53 54 try { 55 out.write(sb.toString().getBytes()); 56 out.flush(); 57 } catch (IOException e) { 58 throw new BuildException("Unable to write summary output", e); 59 } finally { 60 if (out != System.out && out != System.err) { 61 try { 62 out.close(); 63 } catch (IOException e) {} 64 } 65 } 66 } 67 68 public void setFiltertrace(boolean b) { 69 filtertrace = b; } 71 72 public void setOutput(OutputStream out) { 73 this.out = out; 74 } 75 76 public void setRunner(Runner testrunner) { 77 runner = testrunner; 78 } 79 80 public void setSystemError(String err) { 81 systemError = err; 82 } 83 84 public void setSystemOutput(String out) { 85 systemOutput = out; 86 } 87 88 public void startTestSuite(QuiltTest suite) {} 89 90 92 public void addError(Test test, Throwable t) {} 93 94 public void addFailure(Test test, Throwable t) {} 95 96 public void addFailure(Test test, AssertionFailedError t) { 97 addFailure(test, (Throwable ) t); 98 } 99 100 public void endTest(Test test) {} 101 102 public void startTest(Test t) {} 103 104 109 public void setWithOutAndErr(boolean value) { 110 withOutAndErr = value; 111 } 112 } 113 | Popular Tags |